Why triple equal signs is preferred in JS?

Understanding equality signs in Javascript


This sign === is preferred over this sign == in Javascript. There are two reasons.


== is an Abstract Comparison while === is a Strict Comparison.

Abstract Comparison will attempt to convert its argument to a common type before comparison while Strict Comparison uses the obvious semantics which is a value (or any value) is only equal to itself. *There is a slightly different semantics used in numbers. But in most cases, a value is only equal to itself; number 2 is not equal to string 2.


In Javascript, the === sign is preferred over the usual equality sign because of its strict comparison, hence the name.


No Comments Yet