The “best” way is the way you and your colleagues decide upon and verify with a linting tool.
Here are some suggestions:
var a;
var b;
var c;
a = false;
b = "";
c = {};
–
var a = false;
var b = "";
var c = {};
–
var a = false, b = "", c = {};
–
var a = false,
b = "",
c = {};
–
var a, b, c;
a = false;
b = "";
c = {};
I don’t know enough about the different JavaScript engine vendors to make this statement but my assumption is that all of the above are functionally and performance equivalent. If you are using a minifying tool like YUICompiler or Google Closure Compiler the above samples will all compile to the same output*.
* It looks like Google Closure Compiler likes to keep the var
and definition separate if you had that in your original code. var a,b,c;a=!1;b="";c={};
vs var a=!1,b="",c={};
1
solved Declaring JavaScript variable [closed]