let的基本用法

let

同时定义多个变量

let a;
let e, b, c;
let name = 'nb', age = 18, height = [];

变量不能重复声明,使用var却可以!

// 变量不能重复声明
let school = 'xd'
let school = 'nb'

var test_school = 'xd'
var test_school = 'nb'

image-20210103142312306

let 拥有块级作用域,var属于全局变量!

{
    let sex = '男';
    var test_sex = '女'
}
console.log(sex)
console.log(test_sex)

结果:

image-20210103184722715

posted @ 2021-01-03 18:48  牛逼如我也要多思考  阅读(556)  评论(0编辑  收藏  举报