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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:33:57+00:00 2026-06-01T18:33:57+00:00

I am actually a newbie to javascript and just to learn the basics, I’ve

  • 0

I am actually a newbie to javascript and just to learn the basics, I’ve started taking lessons on codecademy.

var i;
for (i = 1; i <= 40; i++) {
  console.log("i is now equal to " + i);
}

Here’s my question – In this code, when i <= 40, it should print till 41, no? Because the for loop continues to run until the condition i <= 40 is true but why is that it only prints till 40 then?

i.e.

When it runs at 40, it would print till 41 by incrementing it once, no? Then why is it that it prints only till 40?

If someone also explained me what exactly the code does and what each line means and does, I’d be really very grateful. Thanks.

  • 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-01T18:33:59+00:00Added an answer on June 1, 2026 at 6:33 pm

    it says the following

    var i; // DECLARE A NEW VARIABLE NAMED i
    
    // set i to 1 and do things while i is less than or equal to 40
    // after this block of code has executed increase the counter by 1
    
    for (i = 1; i <= 40; i++) {     
      console.log("i is now equal to " + i);  // print "i is now equal to <the value of i>"
    }
    

    this means it will print out the number 1 the first time and each time increment by 1 until such time i is equal to 41 at which time the loop will finish (but will do no more operations between the {‘s meaning 41 will never be printed)

    if you had written the following

    for (i = 0; i <= 40; i++) {     
      console.log("i is now equal to " + i);  // print "i is now equal to <the value of i>"
    }
    

    it would make no different aside the count would start from 0, one more iteration but it would still exit when i became equal to 41 but it still wouldn’t print 41

    If you were to do another log statement outside the loop you’d find that i is equal to 41 but this value was never used in the body of the loop (the bit in curly braces)

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

Sidebar

Related Questions

I'm a newbie playing around with Lisp (actually, Emacs Lisp). It's a lot of
I'm javascript newbie...please bear with me. Modified some jQuery animation code from w3c tutorial.
I'm a newbie in jQuery... I've used one jQuery plugin (Actually SimpleModal Plugin) in
Bit of a JavaScript newbie here - I am firing this basic bit of
Just a newbie question really. Can you edit a website (in Visual Studio) on
Just a newbie with iPhone development.. I just have a small problem but huge
I'm still a newbie with Rails (and actually development period). I'm using Rails 3.
I'm newbie in Python, but this question is not a homework (actually this code
Actually, the question is more complex than as it is described. I am newbie
I am a complete newbie when it comes to JS. I actually paid someone

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.