Type coercion is one of JavaScript's most misunderstood features. Understanding the rules eliminates "wat" moments.
Explicit vs Implicit Coercion
ToNumber Rules
ToString Rules
ToBoolean Rules (Falsy Values)
The + Operator
== vs === Deep Dive
Best Practices
- Always use
===except when intentionally checking null/undefined (x == null) - Be explicit: use
Number(),String(),Boolean()instead of implicit coercion - Know the falsy values — they come up in interviews constantly