Table of contents
var - ES5 variable declaration method
let——ES6 variable declaration method
const——ES6 variable declaration method
let const var summarizes:
var - ES5 variable declaration method
- When the variable is not assigned a value, the variable is undefined (it is also undefined when the variable is declared using)
- Scope - the scope of var is the method scope; as long as it is defined within the method, the code after defining the variable in the entire method can be used.
let——ES6 variable declaration method
- If you use the variable directly before it is declared, an error will be reported.
- Scope - let is block scope - usually let has a smaller scope than var
- let prohibits repeated declaration of variables, otherwise an error will be reported; var can be declared repeatedly
const——ES6 variable declaration method
- const is the constant declaration method; it must be initialized when declaring a variable, and the value of the constant cannot be modified in subsequent code.
- What const actually guarantees is not that the value of the variable cannot be changed, but that the memory address pointed to by the variable cannot be changed.
Front-end interview JS— let const var
Guess you like
Origin blog.csdn.net/qq_62799214/article/details/134758872
Recommended
Ranking