As follows:
Copy codeCode: var a = 3;
There are two steps:
1. initialize a as undefined.
2 a value 3
So there will be some "Incredible" phenomenon, that is, the variables in JS can be used first and then declared. This is not allowed in Java.
Copy codeThe Code is as follows: System. out. println ();
Int a = 1;
Compilation and translation fail. But JS can, as shown below:
Copy codeThe Code is as follows: alert ();
Var;
Although it is undefined, no error is reported. It indicates that a is indeed declared and is undefined.
If it is just "alert (a)" and there is no "var a", the JS engine will report an error.
Copy codeThe Code is as follows: alert ();
FF is as follows:
Although it can be used before Declaration, this will cause loss of the effect of the assignment. As follows:
Copy codeThe Code is as follows:
Alert ();
Var a = 1;
The output is still undefined rather than 1.
Another example,
Copy codeThe Code is as follows:
Alert ('A' in window); // true
Var;
Although the Code form is written in alert, the engine automatically processes the declaration of var. The final output is true.
It is not difficult to understand the running results of the following code.
Copy codeThe Code is as follows:
If (! ("A" in window )){
Var a = 1;
}
Alert ();