2

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?

3 Answers 3

4

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 var statement (onevar), but I really don't find that necessary.

Sign up to request clarification or add additional context in comments.

Comments

2

No. It's just a matter of code readability.

Comments

1

memory allocation is done internally using different memory locations (storage wise), therefore it really does not make difference to use with a single declaration or multiple declaration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.