We all know that the declaration of variables in JS is to advance, the following are 4 examples:
1.if (! " T "in window) {
var t = 1;
}
Alert (t), theanswer is undefined, why, because the variable declaration is in advance, so t is inside the window object, but did not go the following judgment, so there is no assignment, the answer is Undefine
2.var num = 100;
function fn () {
var num = num + 1;
return num;
}
Falert (n ()); The answer is still nan, because in the function body first put the Var num ahead, so at the time of assignment, the value of num + 1 is undefined, so the answer is Nan after the operation, remember when we look for the object is
Level to look up, can not find the outside.
3.var B = (function () {
function fn () {
return 1;
}
return fn ();
 FUNCTION fn () {
return 2;
}
var fn;
 FN = 3
}) ();
Alert (b); The answer is 2, because the VAR FN is first advanced, then the function body is defined as a function declaration, and the function declaration will precede the same name parameter, so is Var, FN,FN, and then Renturn, did not go after the fn=3, so the answer is 2
4.function AA (A,b,c) {
function A () {}
Console.log (a);
Console.log (AA);
Console.log (arguments);
var a = "ee";
var AA = "444";
arguments = 6;
Console.log (a);
Console.log (AA);
Console.log (arguments);
}
AA (n/a); The answer is function A () {}
Undefined
[function,2,3]
Ee
444
6 when we understand the variable declaration, we start with Var, then the function body, and finally the argument
The declaration of variables in JS