Possible Duplicate:
Difference between using var and not using var in JavaScript
What is the advantage of initializing multiple javascript variables with the same var keyword?
I have the following code:
var row = $link.attr('data-row'),
a = 2,
b = a;
Is this exactly the same as:
var row = $link.attr('data-row');
var a = 2;
var b = a;
When I use jslint it keeps suggesting I use just the one var. What do people normally do to make the code most readable. Also is there a way to stop jslint complaining?
There is no practical difference. Use whichever suits you best. You can tell JSLint to allow many
varstatements by adding the following directive at the top the file:Note that there is no difference in speed between the two variants:
The part of the spec that deals with variable declarations states the following:
There is nothing in there that would differentiate between separate and combined
varstatements.