Declaring multiple variables in JavaScript

后端 未结 17 982
时光说笑
时光说笑 2020-11-22 13:16

In JavaScript, it is possible to declare multiple variables like this:

var variable1 = "Hello, World!";
var variable2 = "Testing...";
var          


        
17条回答
  •  暖寄归人
    2020-11-22 13:21

    Another reason to avoid the single statement version (single var) is debugging. If an exception is thrown in any of the assignment lines the stack trace shows only the one line.

    If you had 10 variables defined with the comma syntax you have no way to directly know which one was the culprit.

    The individual statement version does not suffer from this ambiguity.

提交回复
热议问题