1、ES6 === let && const

来源:互联网 发布:jre windows x64 编辑:程序博客网 时间:2024/03/29 16:19
// let 的特性if(true){  var a = '苹果';  let b = '香蕉';}alert(a);// 苹果alert(b);// b is not defined{  let c = '橘子';}alert(c);// c is not defined


// const 的特性(常量)const d = '西瓜';alert(d);// 西瓜const d = '柠檬';alert(d);// Identifier 'd' has already been declared// const限制的是给这个常量赋值的动作,不是值本身const fruit = [];fruit.push('樱桃');fruit.push('车厘子');alert(fruit);// 樱桃,车厘子fruit = ['火龙果'];alert(fruit);// Error


原创粉丝点击