NetEase front-end micro-major, JavaScript programming Basics: Functions

Source: Internet
Author: User

JS in the function key word is function, note the following:

function Add (NUM1, num2) {
return NUM1 + num2;
}

1, if the incoming var sum = Add (1, 6, 7); Only 1 and 6 are taken, and the last extra parameter is ignored.

2, if only add (1) is passed in, a nan is obtained because the function's formal parameter num2 is treated as undefined

3, the inside of the function has a arguments array, which is used to store the parameter list passed in, as the following is all the input parameters.

function Add (A, b) {    var sum= 0;    for (var i=0; i< arguments.length; i++) {        sum+=arguments[i];    }    return sum;} var sum = Add (1, 6, 7); Console.log (sum);


4,The parameter is a value pass for the original type (that is, a copy is passed to it), and the argument is a reference pass for the object type (that is, the pointer is passed).

function Increment (a) {    a = a + 1;    return A;} var b = 4;var test = increment (b); Console.log (test); Console.log (b); var person = {    age:10,    name: ' Yanzi '};functi On addage (person) {    Person.age = person.age + 1;} Addage (person); Console.log (person.age);



NetEase front-end micro-major, JavaScript programming Basics: Functions

Related Article

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.