You would think, how difficult could it be to compare two values. Well here in JavaScript, it’s a bloody mess. In JavaScript, there are two ways to compare two values. Either we can check two values for the likeness or we can check whether two values are strictly equal in every which way.

● Strict Equality

The Strict Equality operation is what we are used to. Instead of usual == (double equals) operator, we use === (triple_ equals_) operator to perform strict equality check. In this operation, A === B, both A and B should be of the same type else the result will be always false since two values of different data types can’t be equal in any universe. If both have the same data type, then their values are compared.

Image for post

(equality/strict.js)

In the above example, we have compared two values together using strict equality operator (===). These values could be as simple strings and booleans of primitive data types or abstract/complex data types such as arrays and objects. It produces the following result.

Image for post

#nodejs #es6 #ecmascript #web-development #javascript

Loose vs Strict Equality in JavaScript
1.55 GEEK