There has always been a bug in js which is var:
1. Variables declared by var will have variable promotion
1 |
|
2. Var does not have block-level scope
1 2 3 4 |
|
3. var can be used to define a variable multiple times, and the subsequent variable replaces the previous variable
1 2 |
|
Newly defined variables let:
1. Variables declared by let will not be promoted. They can only be used later if they are defined in the front.
1 |
|
2. let has block-level scope
1 2 3 4 5 |
|
3. let cannot redefine a variable multiple times
1 2 |
|
Constant: refers to data that will not change
1. The value cannot be changed
1 2 3 4 5 6 7 |
|
2. Constants have block-level scope
1 2 3 4 |
|
3. There is no variable promotion, declare first and then use
1 |
|
4. Constants with the same name cannot be declared
5. An initial value must be assigned, otherwise an error will be reported
1 |
|
6. If an object is declared, the address of the object cannot be changed, but its internal attributes can be changed
1 2 3 4 5 |
|
For example: application scenarios, fixed addresses can use constants
1 2 |
|
1. Determine whether the string "hello word" exists "word"
1 2 |
|
2. ES6 provides includes(): returns a Boolean value, used to determine whether the string contains certain characters
1 2 |
|
3, startsWith(str[,num]): Returns a Boolean value, used to determine whether the string starts with a certain character
1 |
|
//Pass in 2 parameters to this method
var bool3 = str.startsWith('word',6);
console.log(bool3); //true
4, endsWith(str[,num]): Returns a Boolean value, used to determine whether the string ends with certain characters
1 2 3 |
|
5, repeat(num): Pass in a number, this method will repeat the string the number of times corresponding to the number
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 3 4 5 |
|
The above is the detailed content of Detailed syntax of ES6. For more information, please follow other related articles on the PHP Chinese website!