What’s the difference between == and === in JavaScript?

clock icon

asked 404 days ago

message icon

1

eye icon

10

I often see people use == (double equals) and sometimes === (triple equals). What’s the practical difference, and when should I use one over the other?

1 Answer

  • == performs type coercion before comparison:
10 == '0' // true
2'' == false // true
3null == undefined // true
10 == '0' // true
2'' == false // true
3null == undefined // true
  • === checks strict equality without coercion:
10 === '0' // false
2'' === false // false
3null === undefined // false
10 === '0' // false
2'' === false // false
3null === undefined // false

Best practice: Always use === to avoid unexpected type coercion bugs.

1

Write your answer here

Top Questions