JavaScript Basic Teaching argument detailed knowledge _ basics

Source: Internet
Author: User

argument is a special parameter of a function in JavaScript, such as the following, using argument access function parameters to determine whether the function executes

Copy Code code as follows:

<script type= "Text/javascript" >
function SayHello () {
if (arguments[0] = = "Bye")
Return
Else
Alert ("Hello" + arguments[0]);

}
</script>

The length property of the argument can be used to return the number of parameters.

Copy Code code as follows:

<script type= "Text/javascript" >
function Cnumbarg () {
return arguments.length;
}
document.write (Cnumbarg (25,2255, "hello") + "<br>");/return 3
document.write (Cnumbarg () + "<br>");//0
document.write (Cnumbarg (1111) + "<br>");//1
</script>

Using argument objects to simulate overloads of functions

Copy Code code as follows:

<script type= "Text/javascript" >
function Fnadd () {
if (arguments.length = 0)
Return
else if (arguments.length = 1)
return arguments[0] + 5;
Else (Arguments.length >1)
var isum =0
for (var i=0;i< arguments.length;i++)
Isum + = Arguments[i];
return isum;
}
document.write (Fnadd (5) + "<br>");
document.write (Fnadd) + "<br>");
document.write (Fnadd (10,20) + "<br>");
document.write (Fnadd (10,20,30,40) + "<br>");
</script>

Small partners are not argument have a new understanding of it, in fact, he can do more things, children's shoes themselves think more do try.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.