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

  • SEARCH
  • Home
  • 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 7977691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:16:34+00:00 2026-06-04T09:16:34+00:00

Reading the code of many javascript libraries, I see that many developers use to

  • 0

Reading the code of many javascript libraries, I see that many developers use to set variables as soon as they were created them.

var i = 0,
var c = 0;

I prefer instead to defined vars after created them.

var i,
    c;

i = 0;
c = 0;

But there might be an explanation about why this or that way?

  • 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-04T09:16:36+00:00Added an answer on June 4, 2026 at 9:16 am

    It’s purely style. Some people prefer to have their declarations isolated from initialization, others like to do it in one. To the JavaScript engine, they’re actually identical, because it handles var prior to the first line of code of the function actually executing. (Note how that is different from some other languages.) That is, it quite literally treats your two examples identically: First it creates i and c with the value undefined, and only later when it starts executing the step-by-step code of the function does it set i to 0 and then c to 0. (This is covered in some depth in Section 10.4.3 and Section 10.5 of the spec.)

    For me, as long as I stick with simple values, I like to do them in one (although I always used to be a “purist” about keeping them separate; I did a lot of silly things when I was younger). But I try to avoid complex logic in the initialization. Sometimes I find I’ve written half my function as a series of comma-delimited statements starting with var, and that starts to get hard to read and maintain so I tend to pull them out at that point.

    On the other hand, a reason to keep them separate is it gives you plenty of room to comment them. 🙂

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

Sidebar

Related Questions

I`m reading the code of some open source project. I see that in one
I am reading existing code. I noticed that there are many data object files
After reading through many code examples for Google Guice, I see a lot of
I am reading cpython code for python 3k and I have noticed, that __missing__
I was reading Code Complete 2 and it mentions this: Many version-control tools wil
I strongly believe that, reading code and reading good code is key to great
I've been reading Code Complete lately, based off of many references here and also
I've been reading up on SharePoint 2010 for work and I've noticed that many
I'm beginning my journey with JavaScript and programming in general. Not having many developers
From reading many articles, such as How do I include a JavaScript file in

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.