Variables and scopes

Source: Internet
Author: User
1. For outer variables, the inner layer can find the (global) inner layer variables, and the outer layer cannot find (local) 2. When VaR is not added, the global variables will be automatically generated (it is not recommended to write this way, it is best to add all the variables to be defined with VAR) 3. The search for variables is based on the proximity principle. The variables defined by VAR are, when the nearest area is not found, the outer layer is located, and the outer layer is located one by one. 4. When the parameter and the local variable have the same name, the priority is the same. 5. The value assignment of the basic type is only worth the value assignment, rather than the reference relationship, and there is a reference relationship between objects (the addresses inside are the same). Basic Type: var A = 5; vaR B =;
B + = 3;
Alert (B); // 8
Alert (a); // 5 object type: var A = [1, 2, 3];
VaR B =;
B. Push (4 );
Alert (a); // [1, 2, 3, 4]
Alert (B); // [1, 2, 3, 4] var A = [1, 2, 3]; var B =;
B = [1, 2, 3, 4]; // It is not a public address, but a newly created
B. Push (4 );
Alert (a); // [1, 2, 3]
Alert (B); // [1, 2, 3, 4]

Variables and scopes

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: 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.