We all know that the declaration of variables in JS is to advance, there are 4 examples:
1.if (! " T "in window) {
var t = 1;
}
Alert (t); The answer is undefined, why, because the variable declaration is ahead of time. So t is inside the window object, but does not follow the following inference. So there's no assignment, and 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, first go to the scope chain to find num This parameter is found in this function. But found that there is no assignment, the value in num + 1 is undefined, so the answer is Nan after the operation, remember when we look for the object is
Level to find above. I can't 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 be after the same name, so it is Var, fn,fn, and then Renturn, 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. First it's Var, then the function body, and finally the number of references.
The declaration of variables in JS