What is the difference between the !==
operator and the !=
operator in JavaScript? Does it behave similarly to the ===
operator where it compares both value and type?
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. The == operator will compare for equality after doing any necessary type conversions.
The === operator compares operands and returns true if both operands are of same data type and have some value, otherwise, it returns false. The !== operator compares operands and returns true if both operands are of different data types or are of the same data type but have different values.
The != operator compares the value or equality of two objects, whereas the Python is not operator checks whether two variables point to the same object in memory.
The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
Yes, it's the same operator like ===
, just for inequality:
!==
- returns true if the two operands are not identical. This operator will not convert the operands types, and only returns false if they are the same type and value. —Wikibooks
Yes, !==
is the strict version of the !=
operator, no type coercion is done if the operands are of different type:
0 != '' // false, type coercion made 0 != '0' // false false != '0' // false 0 !== '' // true, no type coercion 0 !== '0' // true false !== '0' // true
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