Jacob Harvey
PRO
3 months ago
Jacobcountry asked

In JavaScript, what is the difference between equal to (==) and strictly equal to (===)?

Abhay Jajodia
Expert
last month
Abhay Jajodia answered

Hi Jacob,

== compares values after JavaScript may convert one type to another (type coercion).
=== compares both the value and the type, with no conversion.

Example:

5 == "5"    // true (string "5" is converted to number)
5 === "5"   // false (number vs string)

Most of the time, === is safer because it avoids surprising conversions.

If you have more questions, I am here to help 😊

JS
This question was asked as part of the Learn JavaScript Basics course.