Beginners JavaScript, = = and = = Some confused, check the information, found a very good article, reproduced, but also as their own collection
Original address: http://blog.csdn.net/wang171838/article/details/8554305, really very good, the following is the text
JavaScript supports "=", "= =", and "= = =" Operators. You should understand the differences between these (assignment, equality, identity) operators and use them carefully during the encoding process.
A comparison of JavaScript objects is a reference comparison, not a comparison of values. The object and itself are equal, but not equal to any other object. If two different objects have the same number of attributes, the same property names and values, they are still unequal. An array element of the corresponding position is equal to two arrays that are not equal.
The strict equality operator "= = =" First calculates the value of its operand, and then compares the two values, and the comparison process does not have any type conversions:
- If the two value types are different, they are not equal.
- If two values are null or both are undefined, they are not equal.
- If two values are Boolean true or false, they are equal.
- If one of the values is Nan, or if two of the two values are Nan, they are not equal. Nan and any other values are not equal, including IT itself!!! By x!==x to determine if X is Nan, the value of this expression is true only if X is Nan.
- If two values are numbers and the values are equal, they are equal. If one is 0 and the other is-0, they are equally equal.
- If two values are strings and the 16 digits on the corresponding bits contained are exactly equal, they are equal. They are not equal if they are of different lengths or content. Two strings may have exactly the same meaning and the displayed shot characters are the same, but with a different encoded 16-bit value. JavaScript does not standardize the conversion of Unicode, so strings like this are not equal to the results of comparisons with the "= = =" and "= =" operators.
- If two reference values are the same as an object, an array, or a function, they are equal. If you point to different objects, they are unequal. Although two objects have exactly the same properties.
The equality operator "= =" is similar to the identity operator, but the comparison of equality operators is not strict. If the two operands are not of the same type, then the equality operator tries some type conversions and then compares them:
- If the two operands are of the same type, the exact equivalent comparison rules described above are the same. If they are strictly equal, then the comparison results are equal. If they are not strictly equal, the comparison results are unequal.
- If the two operand types are different, the "= =" equality operator may also consider them to be equal. Detection of equality will be governed by the following rules and type conversions:
- If one value is null and the other is undefined, then they are equal.
- If one value is a number and the other is a string, the string is first converted to a number and then compared using the converted value.
- If one of the values is true, it is converted to 1 and then compared. If one of the values is false, the base is converted to 0 and then compared.
- If one value is an object and the other value is a number or string, the object is converted to the original value and then compared. The object is converted to the original value by the ToString () method or the ValueOf () method. The built-in class of the JavaScript core first attempts to use valueof () and then attempts to use ToString (), except for the date class, which uses only the ToString () conversion. Objects that are not in the core of the JavaScript language are converted to the original values through the methods defined in their implementation.
- Comparisons between the other different types are not equal.
JavaScript = = = and = = =