Option1 : multiple var without assignment
function MyFunction() {
var a = null;
var b = null;
....
var z = null;
a = SomeValue;
In Chrome, execution times are identical.
The only real consideration here is optimizing network transfer.
Consider var a=1;var b=2;...;var z=9;
versus var a=1,b=2,...,z=9;
If you put a ;var
in front of each identifier, that's 5 bytes (assuming a single-byte character encoding), versus 1 byte for a ,
. Thus, declaring 26 variables, you can save 100 bytes by writing var
once and listing identifiers with commas.
Granted it's not a huge savings, but every byte helps when it comes to pushing bits over the network. It's not something to worry a great deal about, but if you find yourself declaring several variables in the same area, using the variable declaration list is an easy way to shave a few bytes off your JS file.