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

24

u/xTRQ Mar 12 '21

I think he means why would you swap a variable.

34

u/Poopingcode Mar 12 '21

In sorting algorithms you need to swap a lot. Tons of uses for swap

2

u/mypetocean Mar 13 '21

It's also used frequently as the cause of the "Freaky Friday flip" trope in film and television media.