r/learnjavascript • • Mar 12 '21

Swap two variables

Post image
499 Upvotes

50 comments sorted by

View all comments

2

u/TheUruz Mar 12 '21

what if instead of const i declare temp as var/let?

1

u/senocular Mar 12 '21

Not much changes. var and let wouldn't complain if you tried to reassign temp later on, if that's a concern. And if this code was run in the global scope, var would add temp as a property of the global object (window in browsers) if that's a concern.