Choose strict equality and explicit conversion when comparing JavaScript values.
The move: make conversion visible. A comparison should answer one business question. Are these two IDs the same? Is this count zero? Has the status changed? Loose equality can answer a different hidden question: can JavaScript convert these into something that looks the same? Strict equality === checks equality without broad type coercion. If the values have different types, the comparison is false. That makes it easier to reason about because the operator does not also perform data cleanup. Explicit conversion Sometimes the right move is to convert. Form inputs arrive as strings. URL params arrive as strings. APIs may…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in