简体   繁体   English

ES6 无声明的解构赋值

[英]ES6 Destructuring assignment without declaration

What's the difference between the following syntax?以下语法有什么区别? Will the second one generate global variables?第二个会生成全局变量吗?

// 1. use let or cont
let [a, b] = [1, 2]

// 2. without using let or const 
[a, b] = [1, 2]

Provide me any official reference would be appreciate.向我提供任何官方参考将不胜感激。

The first example defines the variables within block scope.第一个示例定义块范围内的变量。

The second example defines the variables globally.第二个示例定义全局变量。

See the MDN pages . 请参阅 MDN 页面

I'd assume that no declaration type would result in the array being initialized like a let , based on what I'm reading here .根据我在此处阅读的内容,我假设没有声明类型会导致数组像let一样被初始化。

let is block scoped and var is function scoped, perhaps you could check this yourself? let是块作用域, var是函数作用域,也许您可​​以自己检查一下?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM