JS basic knowledge = = operator

Source: Internet
Author: User

= = Comparison of the rules in JS: tend to digitize (comparisons between different data types, excluding obj and obj)
= = between obj and obj compares only the address values stored in the stack

= = Operator parsing ①

First, the data types in JavaScript are divided into two groups:
1.String, Number, Boolean, and object (available)
2.Undefined and Null (none)
The comparison between 3.1 and 2 is false
The comparison between 4.Undefined and Null is True
5. Nan is not equal to Nan

Null and undefined had to say the story (the original intention of the designer)
If you're going to assign a variable to the value of the object type, but it's not assigned yet,
Then you can use NULL to indicate the state at this point (one of the evidences is that typeof null results in ' object ')
Conversely, if you're going to assign a variable to a value of the original type, but it's not yet assigned,
Then you can use undefined to represent the state at this time.

= = Operator parsing ②

parseint (value)
Parsefloat (value)
Conversion situation
String-as long as the highest bit is a number, it is converted to a numeric value; otherwise converted to Nan
Other->nan

Number ()
Conversion situation
is to remove the whitespace characters on either side of the string, and then remove the quotes on both sides to see if it can form a valid number.
If so, the result is this number; otherwise, the result is Nan.
Of course there are exceptions, such as the result of converting a blank string to a number is 0.

Boolean:true==>1
False==>0
Null==>0
Undefined==>nan
Object==>nan

= = Operator parsing ③

As can be seen from this example, the rules of the ToString () and valueof () methods of the built-in objects need to be remembered in addition to the two classifications in mind to grasp the rules of the = = operation.
Includes object, Array, Date, Number, String, Boolean, and so on

= = Operator parsing ④

undefined = = NULL, the result is true. And the result of comparing them to all other values is false.

String = = Boolean, which requires two operands to be converted to number at the same time.

String/boolean = = number, need String/boolean to number.

Object = = Primitive, requires object to Primitive (specifically through the valueof and ToString methods).
(Date tostring valueof)

JS basic knowledge = = operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.