console.log(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;
2.let和const声明形成块作用域
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这个变量
3.var声明的变量会挂载在window上,let和const不会
var a =100;
console.log(a,window.a);// 100 100
let b =10;
console.log(b,window.b);// 10 undefinedconst c =1;
console.log(c,window.c);// 1 undefined
4.同一作用域下var可以声明同名变量,而let和const不可以
var a =100;
console.log(a);// 100
var a =10;
console.log(a);// 10
let b =100;
let b =10;// 控制台报错:Identifier 'b' has already been declared 标识符a已经被声明了。const c=100;const c=10;// 控制台报错:Identifier 'c' has already been declared 标识符a已经被声明了。