var let const 的区别

in 默认分类 with 0 comment
var a = 10; //console.log(a)  10
var a = 100; //console.log(a)  100

let b = 10; //console.log(b)  10
let b = 100; //console.log(b)  控制台会报错Identifier 'b' has already been declared
const c = 10; //console.log(c)  10
const c = 100; //console.log(c) 同上报错,显示标识符已被声明

在同一作用域下let和const不能声明同名变量,var可以

const必须初始化,一旦声明必须赋值,const fgnb会报错Missing initializer in const declaration,而且不能修改

Responses