The
== operator and === operator are used to check whether two values are equal. They use two different definitions with the same characteristics. Both operators accept operands of any type. If the two operands are equal, they both return true, otherwise they return false. The === operator is an equality operator, which uses the strict definition of the same trait to detect two Are the operands exactly the same? Dear friends, please note that they are exactly the same. The == operator is an equality operator that uses a looser definition of identity to compare two operands for equality.
This gives us a basic understanding of the concept.
Let’s talk about the specific situation of determining whether two values are equal.
=== operator compares two values
1, if two value types are different, they are not the same
2. If the type of two values is number and the value is the same, then they are not equal unless one or both of them are (NaN), otherwise they are equal
3. If the two values are strings and the characters at the same position in the string are exactly the same, then they are completely equivalent. If the length or content of the strings are different, then they are not equivalent
== operator compares two values
1, if two values are of the same type, then test their equality. Two values are equal if they are exactly the same. If they're not exactly the same, they're not equal
2, if two values are of different types, they may still be equal (to give a few examples)
1) If one value is null and the other value is undefined, they are equal
2) If one value is a number and the other value is a string, convert the string into a number and compare the converted values
3) If a value is true, convert it to 1 and then compare. If a value is false, convert it to 0 and compare
4) If one value is an object and the other value is a number or string, convert the object into a primitive type value and then compare.