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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:33:06+00:00 2026-05-25T14:33:06+00:00

If I have a = 0; if(a++ < 1){ console.log(a); } I get the

  • 0

If I have

a = 0;
if(a++ < 1){
    console.log(a);
}

I get the value 1 in the console. If a became 1 with the incrementation, then why did the expression evaluate true?

If I do

a = 0;
if(++a < 1){
    console.log(a);
}

Then I don’t get anything in the console, meaning the expression evaluated to be false.

I have always used variable++ to increment variables in for loops and the like. I have seen the ++variable, but I assumed it was another way to write the same thing. Can someone explain what happens and why? What’s the difference between the two?

Does ++variable increment the variable at the time of evaluation, while variable++ increments after?

  • 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-05-25T14:33:07+00:00Added an answer on May 25, 2026 at 2:33 pm

    I have seen the ++variable, but I assumed it was another way to write the same thing.

    No, they’re not the same at all.

    • ++variable is pre-increment.
      It increments variable and evaluates to the new value.

    • variable++ is post-increment.
      It increments variable and evaluates to the old value.

    This is common to most C-style languages, including C itself, C++, PHP, Java and Javascript.

    i.e.:

    Does ++variable increment the variable at the time of evaluation, while variable++ increments after?

    Yes, exactly. 🙂

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

Sidebar

Related Questions

I have a bunch of console.log() calls in my JavaScript. Should I comment them
this is my code and have a error: $('#map_canvas').mouseover(function(e){ console.log(e.offset().left+' '+e.offset().top) }) thanks i
I have the following code where i'm trying to get the c:CreationDate nodes: value
I suddenly get hundreds of these lines in my console log running a process
I have this code : <input id=inputBox /> $('#inputBox').keypress(function(event) { console.log($(this).val()); }); what I
On the one hand if I have <script> var s = 'Hello </script>'; console.log(s);
I have console app A that references another console app B. B app has
I have console application. In that i have some process that fetch the data
I have console application in c. I want to convert into window application, kindly
In a C# console application, is there a smart way to have console output

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.