使用一个表达式将两个变量分配给相同的值? [英] Assign two variables to the same value with one expression?
本文介绍了使用一个表达式将两个变量分配给相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以将两个变量分配给相同的值?
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).
这篇关于使用一个表达式将两个变量分配给相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文