For Example,
//pattern one
function Foo() {
var hello
, world
, how = []
, are
, you = 'you';
}
//pattern two
function Foo() {
var hello;
var world;
var how = [];
var are;
var you = 'you';
}
Would it be more memory efficient to use pattern one, versus pattern 2? Are there other benefits one provides over the other?
No, they’re both exactly the same. Some people prefer doing all variable declarations at the top of the function, because that’s where they effectively are due to hoisting. JSLint also has an option to require a single
varstatement (onevar), but I really don’t find that necessary.