JavaScriptEasy
JavaScript Type Coercion — Implicit vs Explicit Conversion Explained
JavaScript has a small set of primitives and automatic type conversion rules. Understanding coercion helps you predict equality checks, arithmetic, and truthiness in conditionals.
4 concepts·0 practice problems·Beginner level
Key Concepts
- •Seven primitives: string, number, boolean, null, undefined, symbol, bigint
- •typeof null is "object" (legacy quirk)
- •Loose equality (==) coerces types, strict (===) does not
- •+ concatenates when either operand is a string
- •Other math operators convert operands to numbers
- •Truthy/falsy rules drive conditionals and &&/||
Topics Covered
Common Mistakes to Avoid
- ×Using == and expecting no type conversion
- ×Assuming empty strings are truthy
- ×Forgetting that null and undefined only equal each other with ==
- ×Assuming typeof null returns "null"
Interview Tips
- ✓Explain the difference between == and === with examples
- ✓Know the falsy values: false, 0, "", null, undefined, NaN
- ✓Be ready to reason about + with strings and numbers