JavaScript.The.Good.Parts reading notes (i) false value and = = operator _javascript Tips

Source: Internet
Author: User

the fake values for JavaScript are listed below,

Value

type

0

Number

NaN ( non-numeric )

Number

' ( empty string )

String

False

Boolean

Null

Object

Undefined

Undefined

The above values are false values as a criterion, such as:

Copy Code code as follows:

if (undefined) {
Alert (' undefined '); This line of code does not execute
}
while (null)
{
Alert (' null '); This line of code does not execute
}


Although all of these values are equivalent to false, they are not interchangeable.
Some examples are listed below:
undefined = = NULL//false
undefined = = NULL//true

Even
Nan = = Nan//false
Nan = = Nan//false
Ps:nan and Nan are not equal in either operation, isNaN (Nan) can be used to solve the problem of Nan's judgment.

the = = = (!=) operator enforces type conversions, and the conversion rules are quite bizarre. Here are some examples.
Copy Code code as follows:

' = = ' 0 '//False
0 = = ""/True
0 = ' 0 '/True
False = = ' false '//False
false = = ' 0 '/True
false = = undefined//False
false = = NULL//False
NULL = = undefined//True
' \t\r\n ' = 0//True

We recommend using the = = = = (!===) operator.
Related Article

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.