1, the variable follows the first declaration and then use.
Console.log (b); b=123;
Code Run Result:
Uncaught REFERENCEERROR:B is not defined
2. The local variables defined inside the method cannot be accessed externally.
function my () {var a= ' Hi ';} My (); Console.log (a);
Code Run Result:
Uncaught REFERENCEERROR:B is not defined
The same is the error that is not defined by B.
3, one method nested another method, the outside method can access the variables declared inside; (closures implement object-oriented)
function my () {var c=123;function f2 () {console.log (c);} return F2;} var result=my (); result ();
Results: 123
The F2 method calls my c local variable, and the My method returns F2 to invoke the F2 method externally;
4, add var defined local variables, not add to the global variable (no scope problem exists)
On the variable scope of JavaScript