Javascript How to define multiple variables on a single line?

后端 未结 7 2037
渐次进展
渐次进展 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:44

    There is no way to do it in one line with assignment as value.

    var a = b = 0;
    

    makes b global. A correct way (without leaking variables) is the slightly longer:

    var a = 0, b = a;
    

    which is useful in the case:

    var a = , b = a, c = a, d = a;
    

提交回复
热议问题