The difference between using var and let and const in JavaScript

There are big differences in the simple ways of the three life variables.

  First, the difference between the js pre-compilation stage:

    var has variable promotion   

    Let there is no variable promotion. If you declare it before using it, you will get an error.

    const There is no variable promotion. If it is declared before use, it will report an error.

  Declare the difference between basic data type (original data type) and reference data type:

    After var and let are the life variables, when the variable stack data is modified a second time, the variables change immediately.

    But the const life variable holds the data (original value or pointer) in the stack. When modifying the original value (the basic data type, const is immutable.)

  ES5 ------》 var only exists in global scope and function scope.

  ES6 ------ "let and const have the concept of block-level scope.

 

.......To be added

  

  

 

Guess you like

Origin www.cnblogs.com/swt-axios/p/12750975.html