Enhance declare variables and function declarations What is the difference?

(1) variable declaration upgrade: variable declared before entering the execution context is complete.

As long as the variables are declared in the code, whether it be declared on the position at which, js engines will be declared at the top of its range scope;

(2) enhance the function declaration: function will first read the statement before executing the code, which means you can call the function stated in its later statement.

As long as the function declaration in the code, whether it be declared at which position on, js engines will be declared at the top of its range scope;

(3) variable or function declaration: function declaration will cover variable declarations, but will not cover the variable assignment.

A name identifying the same, i.e. there is a var variable declaration, a function declaration another function a () {}, the order, regardless of the function declaration statement will cover both the variable declaration, that is to say, at this time a value is declared function function a () {}. Note: If, after the declaration while initialize a variable, or on a assignment, this time the value of a variable's value. eg: var a; var c = 1; a = 1; function a () {return true;} console.log (a);

Published 67 original articles · won praise 0 · Views 1262

Guess you like

Origin blog.csdn.net/zmmsdk/article/details/104214883