Question d’entretien chez Talroo

What's the difference between the == and === operators?

Réponse à la question d'entretien

Utilisateur anonyme

27 nov. 2017

The `===` operator makes strict comparisons and does not attempt to coerce either value to a different type. Therefore it will fail if values of different types are compared. The `==` operator will attempt to convert both values to the same type. `'1' == 1` (comparing a string representation of the number 1, and an actual number 1) will return true, whereas `'1' === 1` will return false. Strict comparisons are almost always preferable as JavaScript type coercion can have unpredictable side effects.