相关疑难解决方法(0)

是否在ES6中使用let或const声明变量?

我已经玩ES6一段时间了,我注意到虽然声明的变量var按预期提升了......

console.log(typeof name); // undefined
var name = "John";
Run Code Online (Sandbox Code Playgroud)

... 用吊装声明letconst似乎有一些问题的变量:

console.log(typeof name); // ReferenceError
let name = "John";
Run Code Online (Sandbox Code Playgroud)

console.log(typeof name); // ReferenceError
const name = "John";
Run Code Online (Sandbox Code Playgroud)

这是否意味着变量声明let或未声明const?这是怎么回事?这个问题letconst这个问题有什么区别吗?

javascript const let hoisting ecmascript-6

240
推荐指数
5
解决办法
5万
查看次数

标签 统计

const ×1

ecmascript-6 ×1

hoisting ×1

javascript ×1

let ×1