let 关键字
用法与var关键字用法基本一致
- var 关键字用法
var likes = "打羽毛球";
likes="打兵乓球";
console.log(likes);
- let 关键字用法
let food = "西红柿鸡蛋";
food = "红烧肉";
console.log(food);
没有变量提升
- var用法
console.log(gender); //打印: undefined
var gender="男";
相当于:
var gender;
console.log(gender);
gender="男";
- let用法
console.log(author); //直接报错
let author="avaos";