You can swap variables with a destructuring assignment in JavaScript. It takes 1 line of code.
First and obvious, you need two variables.
We declare foo equal to "foo" and bar equal to "bar".
Then you use the destructuring assignent for arrays:
we reassign foo and bar by destructuring from an array containing bar and foo.
Be careful the order is important.
Now we print the variable and see that foo is equal to "bar" and bar is equal to "foo".
You’re now ready to flex your new swapping skills
Hopefully you liked this video 💚
🔥 Subscribe to Bitswired
👍🏽 Leave us a like/comment to support us
💬HASHTAGS:
#javascript #typescript #swap #coding #code #programming #jstricks #jstips #webdevelopment #webapp #webapplication #tech #techtips #web #shorts #short