JavaScript. The. Good. Parts Reading Notes (1) false value and = Operator _ javascript skills

Source: Internet
Author: User
JavaScript false values and operators. If you want to learn about JavaScript, you can check them.

JavaScriptThe list of false values is as follows,

Value

Type

0

Number

NaN (Non-numeric)

Number

''(Null String)

String

False

Boolean

Null

Object

Undefined

Undefined

The above values will all be false values as judgment conditions, such:

The Code is as follows:


If (undefined ){
Alert ('undefined'); // This line of code will not be executed
}
While (null)
{
Alert ('null'); // This line of code will not be executed
}



Although all these values are equivalent to false, they are not interchangeable.
The following are some examples:
Undefined === null // false
Undefined = null // true

Even
NaN = NaN // false
NaN = NaN // false
PS: NaN and NaN are not equal to each other. You can use IsNaN (NaN) to solve the NaN judgment problem.

= (! =) The operator performs forced type conversion, and the conversion rules are quite strange. The following are some examples.

The Code is 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 that you use = (! =) 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.