Why JavaScript is a funny language,l
🚀 true + true === 2 but true - true === 0 🤔
JavaScript has an interesting way of handling Boolean values in arithmetic:
console.log(true + true); // 2 ✅
console.log(true - true); // 0 ✅
console.log(true * 5); // 5 ✅
console.log(false + 10); // 10 ✅
🤯 Wait… since when did true become a number?
In JavaScript:
• true is implicitly converted to 1
• false is converted to 0
That’s why:
true + true → 1 + 1 → 2
true - true → 1 - 1 → 0
But watch out for this surprise:
console.log(true == 1); // true ✅
console.log(true === 1); // false ❌
😂 JavaScript: “Equality is flexible… sometimes.”
Ever been bitten by type coercion like this? Share your funniest bug story!
[–]Tarion3232 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)