Today I see a weird result with the postfix and assignment operator which I was not expecting at all.
let say
let a = 10;
when we increment with postfix, it will result with the addition of 1 as follows
console.log( a++ ); // 10
console.log( a ); // 11
AFAIK a++ is a postfix operation which means
- First, it will use the value(that's why
a++returns10) and then - update the value
- When we print the value, the value has been updated. That's why
areturns11.
So far so good,
But when I assigned the postfix operation to a variable, it won't update the value.
a = a++;
console.log( a ); // 11
Though I was expecting the result to be 12. Why this result? Thanks in advance.
let a = 10;
console.log(a++);
console.log(a);
a = a++;
console.log(a);