Home > Web Front-end > JS Tutorial > What is JS pre-parsing?

What is JS pre-parsing?

PHP中文网
Release: 2017-06-20 10:15:39
Original
2704 people have browsed it

What is JS pre-parsing?
In the current scope, before js is run, there will be code with the var and function keywords declared in advance,
and in memory Arrange it, and then execute the js code from top to bottom.

JS pre-parsing js execution line by line

What does js pre-parse
1> Variables after var
2> Function
3> Variables passed as function parameters

1. When pre-parsing variables defined by the var keyword, all It is a declaration. Regardless of whether it is assigned a value or not, it will be assigned the value undefined.
Whenever passing parameters, assign values ​​directly
alert(a);
var a = 1;
alert(b);
var b = function( ){

}
alert(c);
var c;

2.function is declared and defined when pre-parsing, but it stores The data space stores codes and strings, which is meaningless


alert(a);//function string
function a(){
alert( "Pre-parsed function1")
}

3. The function that you want to execute immediately in the pre-parsing is placed between a pair of () brackets

( function fn(){
alert("Preparsed function1")
}(2)); Closure

(function(){
alert("Prepared function2" )
}());

Under what circumstances will js be pre-parsed
1. When encountering the

Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template