More clarifications needed regarding == vs === in javascript


I am going through Learn JavaScript: Control Flow session. When === was first introduced, it wasn’t clear to me about when and why to use == vs. ===. Found a good answer on StackOverflow but hope the lesson itself could have just-in-time explanations.


From a strict standpoint, there is no coercion when comparing values because they MUST have the same datatype. With loosened constraints, objects can be equal without being identical.

1 == '1'  =>  true

1 === 1   =>  true

1 === '1' =>  false

Coercion is a concept that needs to be learned before it is applied. Nowadays it’s very likely that instruction will tend toward strictness to avoid all the messiness of loose data types. Things can go awry if we are not diligent in our composition of strict code.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.