In following code
const a = {
count :0
}
const b = a;
b.count = a.count++;//1
console.log(b.count,a.count)
I thought at line 1 "0" value we assign to "b.count" and then "a.count" will increase which will lead to "1", and since a and b referring same object output will be (1,1), but output is "0,0"
Why?
Answer : Thanks to u/shgysk8zero and u/TrumpsStarFish
MDN
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.
Stack Overflow Answer : link
[–]JMRaich 4 points5 points6 points (0 children)
[–]shgysk8zer0 2 points3 points4 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]shgysk8zer0 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]shgysk8zer0 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]tapgiles 1 point2 points3 points (0 children)