JavaScript sometimes automatically converts data types when you use ==.
#javascript #typecoercion #jsconcept
JavaScript sometimes automatically converts data types when you use ==.
This is called Type Coercion.
🔹 “” == false → true
• Empty string → 0
• false → 0
• 0 == 0 ✅
🔹 “0” == false → true
• “0” → 0
• false → 0
• 0 == 0 ✅
🔹 “” == “0” → false
• Both are strings
• No type conversion
• Values are different ❌
⚠️ This is why == can be confusing
✅ Prefer === (strict equality) to avoid bugs
⸻
Hashtags (10)
#javascript
#typecoercion
#jsconcept
#webdevelopment
#frontenddeveloper
Comments
Comments from the original post on Instagram
No comments yet
