Comparison is equal in Javascript

Before comparing equal or unequal, will operand type conversion, then compared for equality

When converting different data types, equality and inequality operator follow these basic rules:

1. If the number of the operation is a Boolean value, before comparing for equality first convert value;
2. If one of the operands is a string, the other operand is a value before the first comparison string equality converted into a numerical;
3. If operand is an object, the other operand is not, call the object's valueOf () method, compared with the basic value obtained according to the foregoing types of rules;

These two operators performing the comparison will have to follow these rules:

1.null and undefined are equal.
2. To compare equality before, it can not be converted into any other null and undefined values.
3.NaN not equal to any value
4. If the two operands are objects, they are not the same the comparison object. If both operands are pointing to the same object, then returned to equal true, otherwise false.

the console.log (undefined == null); // to true 
the console.log (null == null); // to true 
the console.log (== undefined undefined); // to true 
the console.log (null == 0); / / false, the equality operator 
console.log (null> = 0); // true, relational operators

Relational operators, the design will always try operand type conversion, and equality operators in the design, is not considered in this respect

Guess you like

Origin www.cnblogs.com/dyongjun/p/11798925.html