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 8007551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:51:59+00:00 2026-06-04T17:51:59+00:00

Suppose I have to write a javascript function: function(){ var a=1; var sum=1; for(var

  • 0

Suppose I have to write a javascript function:

function(){
    var a=1;
    var sum=1;
    for(var i=0;i<6;i++){
        sum=sum+a+1;
    }
    console.log(sum);
}

Someone recommended me to write this function like this:

function () {

   var a = 1;
   var sum = 1;
   for (var i = 0; i < 6; i++) {
      var sum = sum + a +1;
   }
   console.log(sum);

}

With more blank space, I know this rule, but I don’t how it works, or what can I benefit from it?

  • 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-04T17:52:01+00:00Added an answer on June 4, 2026 at 5:52 pm

    It is a matter of opinion what good style is, but in a general sense picking some style and consistently following it throughout your code makes it easier to read (both for other people and for you when you come back to it later).

    In my experience most people find code easier to read with the extra spaces as shown in your second example.

    I don’t like putting a space between function and (). Or, where there is a function name I don’t put a space between the name and the parentheses: function someName().

    Note also that with modern code editors that have syntax highlighting (like Stack Overflow does) it is much easier than it used to be to read code that doesn’t have spaces. Compare the following two:

    for(var i=0;i<6;i++)
    

    for(var i=0;i<6;i++)

    Reading and editing the latter, all in black and white, really annoys me, but I don’t mind the coloured version anywhere near as much. I still prefer it with the extra spaces though.

    I’d make some other changes in your function:

    function() {
        var a = 1,
            sum = 1,
            i;
    
        for(i = 0; i < 6; i++){
           sum += a + 1;
        }
        console.log(sum);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript suppose you have this piece of code: <div> <script type=text/javascript>var output =
Suppose I have a text file with this content: abcdefghk I want to write
suppose I have a html markup like this: <div> <p> this is the parent
I have an external JavaScript that contains: function random_imglink(){ var myimages=new Array() myimages[1]="http://sevir.sitegoz.com/jchs/Banner1.png" myimages[2]="http://sevir.sitegoz.com/jchs/banner2.png"
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
Suppose I have a text variable $$string . How can I write a boolean
Hi I have wrote this code and it suppose to move the object every
I have this method which supposed to get a buffer and write some content
I have this function that I wrote that is supposed to display notifications: function
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then

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.