The equality operator = = and the equivalent operator, = = =, can be used to determine whether the data is equal, return a Boolean type of data, and the = = operator when comparing, the requirement type is not necessarily the same, the value is converted after the data type is equal. When the = = = operator is compared, the requirement type must be the same and the value must be the same.
Condition of = = = Operator:
1, if the types of operations are not the same, then not equivalent;
2, if the operand type is number, then compare two values (any one is Nan, then also not equal) is equal;
3, if the operand type is a Boolean, then the two operands are true or false is equivalent;
4. If the operand type is an object type, then two operands must be referenced to the same object, even if the properties of the referenced two objects are identical, they cannot be judged equal;
5, the operand null equals only null;
6, the operand undefined can only be equated with undefined;
Condition of the = = Operator:
1. If the operands are of the same type, then by the = = = operator;
2. If one operand is number and the other is a Boolean, then the Boolean is converted to 0 or 1, and then the number is equal;
3. If an operand is Nan, the result must not be equal;
4, NULL, Undefined, "", 0, False equal;
5, 1, true equals;
6, non-empty string, true equality;
7, if one operand is number, the other is a string type, then the string is converted to number, and then the number of the judge;
8. If one operand is an object and the other is number or string, then the object is converted to the base type and then compared. When an object is converted to a base type, the ValueOf method of the object is typically called first to return a basic type of data. If the valueof method does not return a basic type of data, then call the ToString method, return a string, and then judge the equality. But the difference is the date object, which is called the ToString method to return a string, and then determine the equality.
The rule for equality conversions is that the operands are converted as far as possible to the number type;
"1" = = true;
The execution of this expression is to convert the string "1" to a value of 1, and then convert the Boolean value true to the value 1, and then determine the equality.
Equality operator = = and equivalent operator = = =