A Simple Method for javaScript to determine whether a string is a number

Source: Internet
Author: User

Copy codeThe Code is as follows:
ParseInt ("Hello", 10); // return NAN
ParseInt ("110", 10); // return 110

Therefore, the simple method to determine whether a string is a number is to use isNaN (). If true is returned, the string is not a number; otherwise, it is a number.
Copy codeThe Code is as follows:
IsNaN (parseInt ("Hello", 10); // true;
IsNaN (parseInt ("110", 10); // false;

Note: The following methods cannot be used for determination:
Copy codeThe Code is as follows:
ParseInt ("Hello", 10) = NaN; // return false
ParseInt ("110", 10) = NaN; // return false

Because NaN does not want to wait for it, this is special. The method for judging NaN uses isNaN ();

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.