Steve Harrison Steve Harrison - 1 year ago 100
Javascript Question

Declaring Multiple Variables in JavaScript

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

var variable1 = "Hello World!";
var variable2 = "Testing...";
var variable3 = 42;

...or like this:

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

Is one method better/faster than the other?

Answer Source

The first way is easier to maintain. Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations.

With the second way, it is annoying to remove the first or last declaration because they contain the var keyword and semicolon. And every time you add a new declaration, you have to change the semicolon in the old line to a comma.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download