国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Javascript call function

Calling the function

When calling the function, just pass in the parameters in order:

abs(10); / / Return 10

abs(-9); // Return 9

Since JavaScript allows any number of parameters to be passed in without affecting the call, pass in There is no problem if there are more parameters than the defined parameters, although these parameters are not required inside the function:

abs(10, 'blablabla'); // Return 10

abs(-9, 'haha', 'hehe', null); // Return 9

There is no problem if you pass in fewer parameters than defined:

abs(); // Return NaN

At this time, the parameter x of the abs(x) function will receive undefined, and the calculation result is NaN.

To avoid receiving undefined, you can check the parameters:

function abs(x) {
    if (typeof x !== 'number') {
        throw 'Not a number';
    }
    if (x >= 0) {
        return x;
    } else {
        return -x;
    }
}

The following case carefully observes how to use the function call

<!DOCTYPE html>
<html>
<body>
<p>點擊這個按鈕,來調(diào)用帶參數(shù)的函數(shù)。</p>
<button onclick="myFunction('學(xué)生','XXX')">點擊這里</button>
<script>
function myFunction(name,job)
{
alert("Welcome " + name + "," + job);
}
</script>
</body>
</html>


Continuing Learning
||
<!DOCTYPE html> <html> <body> <p>請點擊其中的一個按鈕,來調(diào)用帶參數(shù)的函數(shù)。</p> <button onclick="myFunction('Harry Potter','Wizard')">點擊這里</button> <button onclick="myFunction('Bob','Builder')">點擊這里</button> <script> function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } </script> </body> </html>
submitReset Code