Which equals operator (== vs ===) should be used in JavaScript comparisons?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
equals operator (== vs ===) should be used in JavaScript comparisons:
The strict equality operator (
===
) behaves identically to the abstract equality operator (==
) except no type conversion is done, and the types must be the same to be considered equal.Using the
==
operator (Equality)Using the
===
operator (Identity)What is == in JavaScript?
Double equals (==) is a comparison operator, which transforms the operands having the same type before comparison.
So, when you compare string with a number, JavaScript converts any string to a number. An empty string is always converts to zero. A string with no numeric value is converts to NaN (Not a Number), which returns false.
What is === in JavaScript?
=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with “2” using ===, then it will return a false value.
Double equals (==) is abstract equality comparison operator, which transforms the operands to the same type before making the comparison.
For example,
Triple equals (===) are strict equality comparison operator, which returns false for different types and different content.
For example,