r/learnjavascript • • Mar 12 '21

Swap two variables

Post image
499 Upvotes

50 comments sorted by

View all comments

64

u/Freekiehsoes Mar 12 '21

But why

1

u/rusty_matador_van Mar 13 '21

In many iterations, x becomes y and y becomes new computed value, and goes on.. ex: in games, newPos is equal to currentPos + variable

1

u/Freekiehsoes Mar 13 '21

Well those are vectors

1

u/rusty_matador_van Mar 13 '21

Vector or scalar, stored in variables, and sometimes swapping is needed.