Variables that use Var will be declared at the beginning of JS, so the VAR variable declaration order does not affect
1 inch // false 2 inch // true 3 aa=5; 4 var bb=2;
Variables use VAR (explicit declaration) as local variables, variables do not use VAR (implicit declaration) as global variables,
1 function Test () {2 a = "n"; 3 var b = "EAA"; 4 }5Test (); 6 // A 7 // b is not defined
Implicit declaration creates a property of a global object that can be deleted,
1 var a = 5; 2 b=4; 3 Delete A; 4 Delete b; 5 // 5 6 // b is not defined
var a=1; The local variable A is declared and assigned a value of 1;
b=2; First look for a variable B declaration, there is the use of the variable, there is no declaration of a global variable
1 varNUM1 = 1;2num2 = 2;3Console.log ("+num1+", "+num2");// the4+function(){5NUM1 = 11;6 varnum2 = 22;7Console.log ("2--" +num1+ "," +num2);//11,228(function(){9Console.log ("3--" +num1+ "," +num2);//undefined,22Ten varNUM1 = 111; Onenum2 = 222; Anum3 = 333; -Console.log ("4--" +num1+ "," +num2+ "," +num3 ");//111,222,333 - }()) theConsole.log ("5--" +num1+ "," +num2+ "," +num3 ");//11,222,333 - }(); -Console.log ("6--" +num1+ "," +num2+ "," +num3 ");//11,2,333
JavaScript base-var