What is the difference between let and const in es6

WBOY
Release: 2022-03-31 16:18:15
Original
1581 people have browsed it

The difference between let and const in es6 is: the variables declared by let can be changed, and both the value and type can be changed; while the constants declared by const cannot be changed, that is, once const is declared, it must be initialized immediately and cannot be changed later. Assign value again.

What is the difference between let and const in es6

The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.

What is the difference between let and const in es6

The difference between let and const:

  • Variables declared by let Can be changed, both value and type can be changed (let: variables are declared);

  • const declared constants cannot be changed

This This means that once const is declared, it must be initialized immediately and cannot be assigned later.

const i ; // 报错,一旦声明,就必须立即初始化
const j = 5;
j = 10; // 报错,常量不可以改变
Copy after login

The same points between let and const:

  • Both They can only be declared valid in block-level scope

  • and then used after the variable is declared.

  • There is no variable promotion, and there is a temporary dead zone

  • It cannot have the same value as other variables or functions in its scope Name

[Related recommendations: javascript video tutorial, web front-end

The above is the detailed content of What is the difference between let and const in es6. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
es6
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!