Javascript--study

Source: Internet
Author: User

1. Function parameters: passing by value

For numbers, strings, and so on, their values are passed to the function arguments, and the changes to the function parameters do not affect the variables outside the function.

For arrays and objects, etc., the value of the variable of the object (array) is passed to the function parameter, which holds the address to the object (array). When a function changes the contents of an object (array) that the address points to (such as an assignment), it also changes the contents of the object (array) to which the function's external variables are directed, and when the function changes the address of the variable (for example, assignment), it loses contact with the variable outside the function and becomes a completely different object. Does not cause changes to external objects of the function. When a function operates on a variable, it does not lose contact and still operates on the same object

2. Function scope and declaration in advance

var a =1;         function Test () {            alert (a);             var a =2;            alert (a);        }        Test ();         // output undefine and 2        // all variables declared within the function scope of JavaScript are visible inside the        function body // The local variable of the function obscures the global variable of the same name, but it is only copied when the local variable is executed, and is undefined when it is not executed .

Javascript--study

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.