What is the difference between a single comma-separated variable declaration, and multiple declarations?

后端 未结 2 1142
清酒与你
清酒与你 2021-01-22 05:17

What is the difference between comma separated declaration:

var a=0, b=0, c=0;

and multiple line declaration:

var a=0;
var b=0;         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 06:14

    The comma separated declaration is just a short hand. Executing-wise there's no difference. But it can help reduce the size of your javascript file if you are declaring a lot of variables.

    You can even do:

    var a = 1, b = 'string', c = new Date();
    

提交回复
热议问题