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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:25:04+00:00 2026-06-06T10:25:04+00:00

I might be being a bit thicky here but please answer me this. Consider

  • 0

I might be being a bit thicky here but please answer me this. Consider the following code:

a=1;
while(a<=6) {
   console.log(a);
   a++;
}

If I run this I get values in the console from 1 to 6, and then another 6.

Now look at this:

a=1;
while(a<=6) {
    console.log(a);
    ++a;
}

Running this will now get me the values from 1 to 7.

Why is this happening? My understanding was that the statement block would only run if the expression evaluates to true. How can this be possible in the second of my examples? And why does 6 appear twice in the first? Very confusing for me.

If you can explain simply (I’m still learning) that would be great.

  • 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-06T10:25:06+00:00Added an answer on June 6, 2026 at 10:25 am

    The console prints for you the value of the last statement evaluated. In the second case, you pre-increment, so the value of that is 7 and not 6 as in the first one.

    Change you console.log() call to print more stuff and it’ll be obvious:

    console.log("a is: " + a);
    

    You won’t see that prefix on the last line.

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

Sidebar

Related Questions

It might be a long shot posting this question here but we will see.
This might be a very basic question, but I'm getting a bit confused. I'm
Might be a bit of noob question but it's something that's been getting me
might be a silly question nonetheless: I'm playing around with the following code: $a='a';
How might one craft a good explanation of why the following code is not
This might be basic question but how do I create a list of lists
I feel like the answer to this question is really simple, but I really
So in the following bit of code, I really like the verbosity of scenario
Okay, I think I might be over-complicating this issue but I truly am stuck.
This might all be a bit subjective: Our organization has made a strong attempt

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.