Liaoche JavaScript Tutorial Learning Record

Source: Internet
Author: User

$. Data types and variables

1. No distinction between integers and floating-point numbers, unified with number

2. Strings string

3. Boolean values

Attention:

(1)

In fact, JavaScript allows comparisons of arbitrary data types;

Pay special attention to the equality operator == .

The second is the === comparison, which does not automatically convert the data type if the data type is inconsistent, returns false if consistent, and then compares.

Because of this design flaw in JavaScript, do not use == comparisons, always insist on using === comparisons.

(2)

Another exception is that NaN this particular number is not equal to all other values, including itself:

NaN === NaN; // false

The only way to judge NaN is through the isNaN() function:

isNaN(NaN); // true

(3)

Finally, pay attention to the equal comparison of floating-point numbers:

1 / 3 === (1 - 2 / 3); // false

This is not a design flaw in JavaScript. Floating-point numbers generate errors during operation because the computer cannot accurately represent infinite loop decimals. To compare two floating-point numbers for equality, you can only calculate the absolute value of their difference to see if they are less than a certain threshold:

Math.abs(1 / 3 - (1 - 2 / 3)) < 0.0000001; // true

4.null and undefined

nullRepresents an "empty" value, 0 unlike an empty string, which ‘‘ 0 is a numeric value that ‘‘ represents a string of length 0 and null represents "null".

The designer of JavaScript wants to null represent an empty value, whereas the undefined value is undefined. It turns out that there is no such thing as an egg, and the difference between the two is insignificant. In most cases, we should all use null . undefineduseful only when judging whether a function parameter is passed or not.

 

Liaoche JavaScript Tutorial Learning Record

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.