JavaScript is a weak type of language relative to other languages, and in other Java languages, the execution of a program requires a compile stage
There is a similar "precompilation phase" in JavaScript (JavaScript precompilation is scoped to a block of code, i.e., each code block encountered is precompiled > <script></script> execution ),
First, in the popular science of JavaScript in two ways of declaring, Var and function, the former declares a variable, the latter is a method of declaring
In precompilation, JavaScript makes two kinds of processing schemes for both declarations.
<script> var a = "1"; Declare variable a function B () {//Declaration method B alert (); } varfunction() { //Declare variable C alert (); }</script>
In the above code block, a, c is the variable assignment, B is the function declaration, when the above code is executed,
The first step is to go to the pre-compilation stage
Assigning A to a variable, C creates a memory space in memory and points to the variable name, and assigns a value of undefined
For function declarations, memory space is also created, but assigned objects assign values to function names
precompilation phase: (PS: Variables are declared and functions are declaredin the precompilation phase, regardless of the order in which the variables are declared and declared in the code)
<script> var a = undefined; var c = undefined;
var B = function() {alert (); }
</script>
Implementation phase:
<script>= "1"function() {alert (); }</script>
Overall implementation steps:
<script> var a = undefined; var c = undefined; varfunction= "1"function() {alert (); }</script>
Topic:
<script> var a = "1"; function B () {alert (a); var a = "2"; } b (); </script>
PS: Variables and function declarations relative to the window environment, each scoped to the variables and functions under it
<script> Functionhello () { alert ("Hello"); } Hello (); </script> <script> Functionhello () { alert ("Hello World"); } Hello (); </script>
<script>
function Hello () { alert ("Hello"); }
function Hello () { alert ("Hello World"); } Hello (); </script>
Blog: http://www.cnblogs.com/alex-web/
Note: The yy of the Little crazy paper
"Precompilation phase" and "execution phase" during JavaScript run