Will JavaScript initialization be improved?
This article mainly introduces the relevant knowledge of JavaScript initialization will be improved, the content is detailed and easy to understand, the operation is simple and fast, it has certain reference value, I believe that after reading this JavaScript initialization will improve the article will have something to gain, let's take a look.
JavaScript initialization does not promote
Only declared variables in JavaScript will be promoted, not initialized ones.
The results of the following two examples are different:
Example 1
Var x = 5; / / initialize x
Var y = 7; / / initialize y
Elem = document.getElementById ("demo"); / / find the element
Elm [XSS _ clean] = x + "" + y; / / display x and y
Example 2
Var x = 5; / / initialize x
Elem = document.getElementById ("demo"); / / find the element
Elm [XSS _ clean] = x + "" + y; / / display x and y
Var y = 7; / / initialize y
Example 2's y outputs undefined because the variable declaration (vary) is promoted, but initialization (yinitialization 7) is not promoted, so the y variable is an undefined variable.
Example 2 looks like the following code:
Var x = 5; / / initialize x
Var y; / / statement y
Elem = document.getElementById ("demo"); / / find the element
Elm [XSS _ clean] = x + "" + y; / / display x and y
Y = 7; / / set y to 7
This is the end of the article on "will JavaScript initialization improve?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "will JavaScript initialization improve". If you want to learn more, you are welcome to follow the industry information channel.