Javascript How to define multiple variables on a single line?

后端 未结 7 2034
渐次进展
渐次进展 2020-11-28 22:20

Reading documentation online, I\'m getting confused how to properly define multiple JavaScript variables on a single line.

If I want to condense the following code,

7条回答
  •  星月不相逢
    2020-11-28 23:04

    Specifically to what the OP has asked, if you want to initialize N variables with the same value (e.g. 0), you can use array destructuring and Array.fill to assign to the variables an array of N 0s:

    let [a, b, c, d] = Array(4).fill(0);
    
    console.log(a, b, c, d);

提交回复
热议问题