Javascript How to define multiple variables on a single line?

后端 未结 7 2041
渐次进展
渐次进展 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 22:39

    Using Javascript's es6 or node, you can do the following:

    var [a,b,c,d] = [0,1,2,3]
    

    And if you want to easily print multiple variables in a single line, just do this:

    console.log(a, b, c, d)
    

    0 1 2 3

    This is similar to @alex gray 's answer here, but this example is in Javascript instead of CoffeeScript.

    Note that this uses Javascript's array destructuring assignment

提交回复
热议问题