A thread on Swapping two numbers using #Javascript.
What? You thought we always need a 3rd variable for it? Believe me there are at least 4 more ways to do that.. 😅

#100DaysOfCode #CodeNewbie #code @thackingschool @codedotin @iprashanth_ #CodingTips #bootcamp
Let's get it out of our system first 😜. Undoubtedly the most common way to swap two numbers. But where's the fun in it right?

#100DaysOfCode #CodePen #javascript
Idea is simple, get the sum of the two numbers. The numbers can then be swapped by subtracting from the sum. #simple 🤭
But wait, there's more...

#100DaysOfCode #Swap #codinglife
It's basic arithmetic. Dividing the product by any of the operand will always give you the other operand.. Isn't it?
Yes, there are flaws to this approach, like what if one of the number is 0, right? But who said this is the best approach? 😜 I didn't!

#programming #codingisfun
This one is cool! Remember our old friend XOR? He's all grown up and is helping us do cool stuffs 😋. Cant blame you if you don't remember, but he returns 1 if the corresponding bits of two operands are opposite. XOR is weird, it literally can't even #PunIntended

#100DaysOfCode
Finally, here's XNOR. Whatever XOR does, he does the opposite (Rivals! I tell you🤦🏻‍♂️). But they both can get the work done.

#CodingTips #100DaysOfCode #programming
Wow! You read it so far.. Here's a joke for you.
What did the Owner of a 7-bit dog say?
"Don't worry, it doesn't byte!" 😂

#sorrynotsorry #Dontunfollowme
You can follow @WhoAdityaShukla.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: