Home > Article > Web Front-end > Introduction to let and const in ES6
The contents written in this series of blogs are some summaries of my daily studies. They are used as notes and review. If there is something wrong, please point it out, thank you Nonsense Without further ado, let’s get started!
Both let and const can be used to define variables (similar to var), but there are some differences and new features. As shown below
1. let command( is used to declare variables)
1 . Since there is no block-level scope in js, variables declared by let are only valid within the block to which they belong and cannot be accessed externally. (For example, anything within a pair of braces can be understood as a block-level scope)
2. Use es6 syntax to adopt strict mode by default, and undeclared variable references in strict mode An error will be reported
3. You cannot declare the same variable repeatedly using let
2. Const command (Define a constant )
1. Constants declared using const cannot be modified (if a reference type (object) is declared, the pointer cannot be changed, but the content inside can be modified. Modified)
2. const also has a block-level scope like let
3. const declaration Must be assigned
The above is the detailed content of Introduction to let and const in ES6. For more information, please follow other related articles on the PHP Chinese website!