JavaScript Equality Gotcha: == vs ===

I used to think == and === were just “style choices” in JavaScript. They’re not. That assumption once caused a bug that took me way too long to trace. Examples like: 0 == false → true "" == 0 → true null == undefined → true [ ] == false → true made me pause and actually understand what’s happening. Loose equality (==) compares values after type conversion. Strict equality (===) compares value and type, no guessing, no surprises. The scary part? Code with == can look correct and still behave unexpectedly, especially with user input, API data, or conditionals. My biggest learning: Use === by default. Only reach for == when you clearly understand every conversion involved. Have you ever faced a weird bug because of ==? #JavaScript #FrontendDevelopment #WebDevelopment #LearningInPublic #DeveloperJourney

Loose and strict equality checks

Like
Reply

To view or add a comment, sign in

Explore content categories