I borrowed this code from a question that was marked as duplicate and then deleted 1, but because I was not able to find an exact duplicate to it I would like to create a new question for that.
I'm aware of the problems with floating-point arithmetic (Is floating point math broken?), but this special case is still interesting.
The following two snippets look seemingly equal:
let a = 860.42065
a *= 1/860.42065
console.log(a);
let a = 860.42065
a = a * 1/860.42065
console.log(a);
So one could expect that those should have the same outcome because a *= b
is seen as a shortcut for a = a * b
(How does += (plus equal) work?).
But the outcome of the two snippets can be different.