Re:Best Practices Exist For A Reason
by mnutt on Wednesday May 02, 2012 @08:09PM
(#3921789)
With separate var statements, you never end up with this situation:
In 90% of the cases the code will run the same whether or not there is a comma on line 2, but in the other 10% you will get burned in odd ways now that `baz` is a global variable.
[ Parent
| on HN ]
JS Lint is your friend in this case. It will log that
* There's a missing semicolon on line 2
* There's a missing semicolon on line 3
* baz was being used before it was defined.
That's just in a global context. When it's in a function you get a little more:
* the baz line is indented too far - because it's being interpreted as a new statement.
Sure, you could eyeball your code looking for this. Or just use an automated tool that'd do it for you