🔄 Swap Variables without a temp variable
Here’s a quick and cool trick to swap two variables without a temp variable using XOR.
Magic! ✨ Now
Here’s a quick and cool trick to swap two variables without a temp variable using XOR.
a = 5
b = 9
a = a ^ b
b = a ^ b
a = a ^ b
print(f"a = {a}, b = {b}") # a = 9, b = 5
Magic! ✨ Now
a is 9 and b is 5.
Cross Code
https://youtu.be/lmClPGvdWTI
Funny that their is a study that shows as u get more buff u become dumber. Technically speaking, what the study shows is as u use more juice u become dumber. Life responsibly
Hot take 🔥
Types of people you can offend easily:
1. Tech bros
2. LGQHDTV people
3. Women ☕️🗿
Types of people you can offend easily:
1. Tech bros
2. LGQHDTV people
3. Women ☕️🗿
Lies the `===` operator tell. JS👽
Consider:
You could use
✨How to avoid deez pitfalls:
1. Use
2. Use
Object.is(..) in action:
Think of
#JS
=== ( “strict equality” ) operator has some nuances. The === operator is designed to lie in two cases of special values: NaN and -0.Consider:
NaN === NaN; //false
0 === -0 //true
You could use
0 === -0 intentionally in your program for whatever reason. ( I know you lot are weird )✨How to avoid deez pitfalls:
1. Use
Number.isNaN(..) for NaN checks.2. Use
Object.is(..) for -0 comparisons (and for NaN too).Object.is(..) in action:
console.log(Object.is('1', 1));
// Expected output: false
console.log(Object.is(NaN, NaN));
// Expected output: true
console.log(Object.is(-0, 0));
// Expected output: false
const obj = {};
console.log(Object.is(obj, {}));
// Expected output: false
Think of
Object.is(..) as the “quadruple-equals” ====, the really-really-strict comparison!😉#JS
Skywalker Leul
https://youtube.com/shorts/lz1O-rUes-s?si=RFJ6gsm8_JL_jemZ
The man was already retired gymnast in 2004. Damn. Their levels to this shit. 🐐🐐🐐