使用一个表达式将两个变量分配给相同的值?

使用一个表达式将两个变量分配给相同的值?

问题描述:

有什么办法可以将两个变量分配给相同的值?

Is there any way to assign two variables to the same value?

只需尝试一下:

let x, y = 'hi'

并编译为:

'use strict';

var x = void 0,
    y = 'hi';

绝对没有理由比简单地更喜欢破坏性分配

There is absolutely no reason to prefer the destructuring assignment over simply

let x = 'hi', y = x;

这不仅是一个语句,而不是两个语句,而且还避免了额外的分配(所提供的具有解构结构的解决方案在没有充分理由的情况下分配了至少一个对象).

Not only it's one statement instead of two, but it also avoids extra allocations (the provided solution with destructuring allocates at least one object with no good reason).