Possible Duplicate:
Declaring Multiple Variables in JavaScript
I was wondering whether there is a difference in listing variables in JavaScript (and JS libraries).
Example:
var $this = $(this),
$body = $("body"),
$main-wrap = $("body > section.wrapper");
OR
var $this = $(this);
var $body = $("body");
var $main-wrap = $("body > section.wrapper");
I always thought that the difference only lies in notation. The first example is shorter and possibly faster to execute. Recently I did some testing and now I am not sure anymore. Can anyone clear this up?
Is there a difference in execution speed, result, method?
I broke the habit of using multiple
varstatements when I started using jsLint. It always caught that and said that it was faster to separate by a comma.Looking into this more, there seem to be many sources that agree with this.
From jsLint #scope
From A List Apart:
However,
here are two fairly compelling reasons to use multiple
varstatements from SO posters. and here