Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Confused about the postfix increment operator and assignment operator precedence in JavaScript

The operator precedence documentation says that the postfix increment operator have a higher precedence over the assignment operator, but the following example shows that the opposite is true:

var i = 1;

var j = i++;

console.log(j);  // will output 1 (I expected the output to be 2)

Why the output is 1 instead of 2?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The post-increment operator increments the value of the variable, but returns the value before it was incremented. Therefore, j will have a value of 1 while i will have a value of 2.

var i = 1;
var j = i++;
console.log("j =", j);
console.log("i =", i);

See increment operator:

If used postfix, with operator after operand (for example, x++), the increment operator increments and returns the value before incrementing.
If used prefix, with operator before operand (for example, ++x), the increment operator increments and returns the value after incrementing.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!