Is there any way to assign two variables to the same value?
Just tried this:
let x, y = 'hi'
and it's compiling to this:
'use strict';
var x = void 0,
y = 'hi';
Yes, it is possible:
let x, y;
x = y = 'hi';
It is called chaining assignment, making possible to assign a single value to multiple variables.
See more details about assignment operator.
If you have more than 2 variables, it's possible to use the array destructing assignment:
let [w, x, y, z] = Array(4).fill('hi');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With