Why triple equal signs is preferred in JS?

Understanding equality signs in Javascript

What

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

Why

== 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.

Summary

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

Resources

No Comments Yet