1. Variables declared by var will be mounted on the window, while variables declared by let and const will not:
var a =100;
console.log(a,window.a);// 100 100let b =10;
console.log(b,window.b);// 10 undefinedconst c =1;
console.log(c,window.c);// 1 undefined
2. There is variable promotion for var declaration variables, but there is no variable promotion for let and const
console.log(a);// undefined ===> a已声明还没赋值,默认得到undefined值var a =100;
console.log(b);// 报错:b is not defined ===> 找不到b这个变量let b =10;
console.log(c);// 报错:c is not defined ===> 找不到c这个变量const c =10;
3. Let and const declarations form block scope
if(1){
var a =100;let b =10;const c =1;}
console.log(a);// 100
console.log(b)// 报错:b is not defined ===> 找不到b这个变量
console.log(c)// 报错:c is not defined ===> 找不到c这个变量
4. Let and const cannot declare variables with the same name in the same scope, but var can
var a =100;
console.log(a);// 100var a =10;
console.log(a);// 10let a =100;let a =10;// 控制台报错:Identifier 'a' has already been declared ===> 标识符a已经被声明了。
5. Temporary dead zone
var a =100;if(1){
a =10;//在当前块作用域中存在a使用let/const声明的情况下,给a赋值10时,只会在当前作用域找变量a,// 而这时,还未到声明时候,所以控制台Error:a is not definedlet a =1;}