|
|
|
|
|
by ermir
1780 days ago
|
|
I guess it is true in this particular example, since 0 is a primitive and assigned by value. But what if you got it from an outside function, such as init(), and it was an object instead? Then you would have to guarantee that the return value of init() would not change between statements. In the end this shows that JS is unequipped to handle such behavior without significant changes to the core language. |
|
Then even in a synchronous context you'd have no guarantee that it wouldn't be modified:
This has nothing whatsoever to do with sync vs async.It is one of the main reasons people like immutability/functional programming. But that's its own topic.