The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.
== in JavaScript is used for comparing two variables, but it ignores the datatype of variable. === is used for comparing two variables, but this operator also checks datatype and compares two values. Checks the equality of two operands without considering their type. Compares equality of two operands with their types.
JavaScript provides three different value-comparison operations: === — strict equality (triple equals) == — loose equality (double equals)
=== is the strict equal operator. It only returns a Boolean True if both the operands are equal and of the same type. If a is 2, and b is 4,
a === 2 (True)
b === 4 (True)
a === '2' (False)
vs True for all of the following,
a == 2
a == "2"
2 == '2'
=== is 'strict equal operator'. It returns true if both the operands are equal AND are of same type.
a = 2
b = '2'
a == b //returns True
a === b //returns False
Take a look at this tutorial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With