亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

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