Go deep into Nan

Source: Internet
Author: User

Nan, meaning not a nnmber. The main purpose of introducing this numeric type variable in Javascript is to control the situation where "a number is returned but no number is returned. For example, if a number is divided by 0, errors may occur in many other languages, but Nan is returned in JavaScript. This does not affect the process.

Nan has two features: First, any operation involving Nan will return Nan, and second, Nan is not equal to any value, including Nan itself.

For Nan, ecmascript specifies the isnan () function to determine whether it is a number. Let's look at several examples:

In the example, we can see that isnan () will try to convert the passed non-numeric parameter to the numeric type, and return true if such conversion is not possible.

In addition, it should be emphasized that isnan () can operate on objects. When the parameter is an object, the system will try to call the valueof () method of the object and determine whether the returned value can be converted to a value. If the tostring () method cannot be called, the system will test the return value.

The basic process for isnan () operations is as follows:

References: javascript advancedProgramDesign

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.