Back to subject
JavaScript/Operators

See Why === Matters

Practical lesson

Let's compare == and === directly, on values that look similar but aren't identical in type.

const a = 10; is a Number. const b = "10"; is a String that happens to look like the same number. This setup is deliberately chosen to expose the exact difference between the two equality operators.

a == b evaluates to true == converts types before comparing, so it treats "10" as if it were 10 for the purpose of this check, and they match.

a === b evaluates to false === refuses to convert types first. Since a is a Number and b is a String, they're considered different, regardless of what they look like.

This is exactly why === is the recommended default in modern JavaScript: it tells you the truth about whether two values are genuinely the same type and value, rather than quietly converting one to match the other. When in doubt, reach for === first.

Try it yourself
Code

Starter example

Code
<script>
  const a = 10;
  const b = "10";
  document.body.innerHTML = `
    <p>a == b: ${a == b}</p>
    <p>a === b: ${a === b}</p>
    <p>7 % 2: ${7 % 2}</p>
  `;
</script>
Live preview