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

原文地址:https://www.cnblogs.com/NB01/p/14226503.html