a javascript question about destructuring when [a, b] = [b ,a]

时间:2019-05-19 04:04:33

标签: javascript

I met a confuse problem when i use destructuring in javascript. Here is the code:

let a = 1
let b = 2
[b, a] = [a, b]
console.log([a, b])

I expect that variables a and b will exchange their value, but here throw a error, which is "ReferenceError: Cannot access 'b' before initialization". I cannot figure out why this happens.

0 个答案:

没有答案
相关问题