var
1.仅仅声明 默认值是 undefined
2.可以重新赋值
3.作用域是方法内 ,而不是代码块内
1 function test(){ 2 var a ; 3 console.log(a); //undefined 4 5 a = "hello"; 6 console.log(a); 7 8 for(var i=0 ;i < 10 ; i++ ) { 9 var data = "test"; 10 } 11 console.log(i); //10 12 console.log(data); //test 13 14 }

js-var.png
let
1.仅仅声明 默认值是 undefined
2.可以重新赋值
3.块作用域
1 function test(){ 2 let a ; 3 console.log(a); //undefined 4 5 a = "hello"; 6 console.log(a); 7 8 for(let i=0 ;i < 10 ; i++ ) { 9 let data = "test"; 10 } 11 console.log(i); //10 12 console.log(data); //test 13 14 }

js-let.png
const
1.声明时必须初始化
2.不可重新赋值
3.块作用域
4.虽然不可被重新赋值,但是可以改变。
1 function test(){ 2 const a = {"name":"czz","sex":"M"}; 3 console.log(a); 4 a.name = "XL"; 5 a.sex = "F"; 6 console.log(a); 7 }
1 function test(){ 2 const a ; 3 console.log(a); //undefined 4 5 a = "hello"; 6 console.log(a); 7 8 for(let i=0 ;i < 10 ; i++ ) { 9 const data = "test"; 10 } 11 console.log(i); //10 12 console.log(data); //test 13 14 }

js-const.png

js-const-2.png
欢迎大家留言,以便于后面的人更快解决问题!另外亦欢迎大家可以关注我的微信公众号,方便利用零碎时间互相交流。共勉! !
