ES6

1. New syntax in ES6

1.1 Declare variables using the let keyword
Variables declared by let are only valid in the output block-level scope

if(true) {let a=10; }Copy the code

console.log(a);

1.1.2 Variables declared using the let keyword do not have variable promotion
console.log(a);

let a=100;
Before ES6 variables can be used first and then declared
Copy the code
1.1.3 Variables declared with the let keyword have temporary dead zone characteristics
var num=100;if(true) {console.log(num);

let num=20;

}
Copy the code
1.2. Let’s do a classic interview
let arr=[];
for(let i=0; i<2; i++){ arr[i]=function(){
console.log(i);
}
}
arr[0] (); arr[1] ();Copy the code
1.3 const

Function: Declare constant, constant is the value (memory address) can not change the amount;

1.3.1 Has block-level scope
if(true) {const a=10;

}
console.log(a);
Copy the code

1.4 Const let var