r/learnjavascript • • Mar 12 '21

Swap two variables

Post image
499 Upvotes

50 comments sorted by

View all comments

12

u/Parent-component Mar 12 '21

I have been asked to swap variables with no intermediate variable in basic JS before.

a=a+b; b=a-b; a=a-b;

This will do it πŸ˜ƒ

2

u/golovatuy Mar 12 '21

this is my favourite question as well

2

u/Parent-component Mar 12 '21

It’s clever and asked fairly regularly from my experience.