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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:24:29+00:00 2026-06-15T22:24:29+00:00

As far as I’ve been led to understand, x++ is essentially a terser way

  • 0

As far as I’ve been led to understand, x++ is essentially a terser way of saying x = x + 1. So far, so clear. In front-end Javascript, I’ve occasionally seen ++x — I seem to remember from a jsPerf test I can no longer find (how does one Google ++ effectively?) that this somehow had a small performance benefit in a particular version of IE, and let it go at that.

However I’ve recently encountered something that speaks of a weird quirk in execution order (JS code):

var x = 1;
console.log(x++); // 1 (?!)
console.log(x);   // 2

…whereas

var x = 1;
console.log(++x); // 2 (what I would've expected)
console.log(x);   // 2

I can’t get my head around this. How can we return the unmodified variable when the operation and assignment are within the parenthesis, and thus by all rights should be executed before console.log is even invoked, let alone executed and returned?

  • 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-15T22:24:30+00:00Added an answer on June 15, 2026 at 10:24 pm

    Those are two different things

    x++
    

    is a post-increment. It returns x before the change but then changes it:

    tmp = x;
    x = x+1;
    return tmp;
    

    whereas

    ++x
    

    is a pre-increment. It first changes x and returns the new value afterwards:

    x = x+1;
    return x;
    

    The second one is also slightly faster as your compliler/interpreter doesn’t need to create a temporary variable and copy the data across.

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

Sidebar

Related Questions

As far as I understand, there is no way to find out which exceptions
So far I've been setting up redirects for single pages on my ASP.NET site
So far I have only been updated a view from within its controller. I
As far as I know there is no way to migrate existing Facebook comments
So far, I've seen many different naming conventions used for PHP namespaces. Some people
As far as I understand, in Scala we can define a function with no
As far as I understand sp_addextendedproperty is not available in SQL Azure databases as
So far I have been able to compile my Java programs in Linux using
As far as I can tell, these two pieces of javascript behave the same
As far as I know, strings are immutable in Delphi. I kind of understand

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.