7
It has become quite common to declare variables in multiple lines in Javascript. Especially when they are initialized later:
var var1 = null,
var2 = null,
var3 = 0;
The "normal" would be like this:
var var1 = null;
var var2 = null;
var var3 = 0;
- Why multiple declaration of variables on multiple lines has become so common?
- What are the differences between the two?
- When I should wear one or the other?
I’m not a big fan of separating variables with a comma because that makes the first and last lines different from the middle lines. That means we need to edit the line of
var3
if we want to add avar4
on the list. That said, some people find the first version more beautiful.– hugomg
Just to show how it’s more a matter of taste anyway, unlike @hugomg I already prefer to use with commas, so when you need to set several empty variables at the beginning of a function, you can do everything in one line saving characters.
– Kazzkiq