Here's a test situation for using the unary operator "++":
var j = 0 ;
console.log(j);
j = j++;
console.log(j);
For this, the output is:
0
0
Since the ++ operator's position is at the back of the operand, so its precedence is lower than the assignment's precedence, I would expect "j" to first receive the value of itself (i.e.0), but then be incremented. So why is the second console.log(j)
call still showing "0"?
Just to be clear, I know that the solutions are:
// 1)
j++;
// 2)
++j;
// 3)
j += 1;
// 4)
j = ++j;
But I need to know why the increment step is not conducted in this specific scenario, NOT how to fix it!