Scope of the variable

Source: Internet
Author: User

A globally-scoped VariablevarA = 1;//Global VariablesfunctionOne () {alert (a);//Alerts ' 1 '} Local VariablesvarA = 1;function(a) {alert (a);//alert out parameter A's argument, not global variable A's value ' 1 '}//Local Variablesfunctionthree () {varA = 3; alert (a); //Alerts local A's value ' 3 '}intermediate:javascript does not have a similar block-level scope (ES5; ES6 introduction Let)varA = 1;functionFour () {if(true) {    varA = 4; } alert (a); //Alerts ' 4 ', not the value of global variable a ' 1 'properties of the}intermediate:object Property object--varA = 1;functionFive () { This. A = 5;} Alert (NewFive (). a);//Alerts ' 5 'advanced:closurevarA = 1;varSix = (function() {  varA = 6; return function() {    //JavaScript "Closure" means I had access to ' a '    //because it is defined in the function in which I was defined.    //closures Access variables in the parent function,alert (a);//Alerts ' 6 '  };}) (); Advanced:prototype-based scope resolution based on the scope of the prototype http://Stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript--This can not write, source as above, but feel this prototype-based case looked very awkward, and practice a bit, sure enough there is a problem. 

Scope of the variable

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.