Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:10:43+00:00 2026-06-18T15:10:43+00:00

Is it good to declare one variable per var statement, it makes code easier

  • 0

Is it good to declare one variable per var statement, it makes code easier to re-order the lines in the program as per modification needs.

Could somebody make out, is there any difference between following style of declarations in Node.js in terms of execution of code?

//Style 1
var keys = ['foo', 'bar']; var values = [23, 42];

//Style 2
var keys = ['foo', 'bar'], values = [23, 42];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:10:44+00:00Added an answer on June 18, 2026 at 3:10 pm

    You can have multiple var statements in JavaScript; this is called hoisting; However, because you can run into scoping issues, it’s best to use a single declaration in any function.

    It’s common to see this style

    var keys   = ['foo', 'bar'],
        values = [23, 42];
    

    In fact, the very reason JavaScript allows you to chain the declarations together is because they should be happening together.

    To illustrate a scoping issue:

    f = "check?";
    
    var hello = function () {
      console.log(f);          // undefined
      var f = "nope!";
      console.log(f);          // nope!
    };
    
    var hello2 = function () {
      console.log(f);          // check?
      var f2 = "nope!";        // not reusing `f` this time
      console.log(f2);         // nope!
    };
    
    hello();
    hello2();
    

    At first glance, you’d think the first output would be check?, but because you’re using var f inside the function body, JavaScript is creating a local scope for it.

    To avoid running into issues like this, I simply use a single var declaration 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to declare some integer constants in PowerShell. Is there any good
I know it's quite idiomatic, or good style at least, in C to declare
Can a variable declared in one jsp file be used in another, if imported?
I'm not very good with P/Invoke. Can anyone tell me how to declare and
So, I have a variable state in a class. I want to declare it
Possible Duplicate: What describes @property(…) best? What's that actually good for? If I declare
This one may seem trivial to some, but I'm trying to adopt good habits
Is there ever a good reason to not declare a virtual destructor for a
Is it a good idea to have NSSortDescriptor declared static in a Utility class?
Good morning, I have mysql queries where I would like to calculate percentage of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.