Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V7021. The postfix increment or...
menu mobile close menu
Additional information
toggle menu Contents

V7021. The postfix increment or decrement has no effect because the variable is overwritten.

Apr 03 2026

The analyzer has detected an error related to using postfix increment or decrement when writing to the same variable.

The example:

let value = 0;
....
value = value++;  // <=
....

The value variable remains zero after the assignment. This happens because the postfix increment and decrement return the variable value before it is modified. The expression evaluates in the following order:

  • reading the value variable;
  • incrementing the value of the value variable by one;
  • assigning the value obtained in step 1 to the value variable.

As a result, the effect of the postfix increment or decrement is lost when the result is reassigned to the same variable.

This may be a typo, and the result should have been stored in another variable. In that case, the fixed code might look like this:

let value = 0;
let savedValue = ....; 
....
savedValue = value++; 
....

Otherwise, developers might have accidentally written the assignment, even though it is not really needed here:

let value = 0;
....
value++;
....