Home > Web Front-end > JS Tutorial > JavaScript A simple way to determine whether a string is a number_javascript skills

JavaScript A simple way to determine whether a string is a number_javascript skills

WBOY
Release: 2016-05-16 18:49:21
Original
2560 people have browsed it
Copy code The code is as follows:

parseInt("Hello",10);//return NAN
parseInt("110",10);//return 110

So a simple way to determine whether a string is a number is to use isNaN(). If true is returned, then the character The string is not a number, otherwise it is a number
Copy code The code is as follows:

isNaN(parseInt( "Hello",10));//true;
isNaN(parseInt("110",10));//false;

Note: You cannot use the following method to judge:
Copy code The code is as follows:

parseInt("Hello",10)==NaN;// return false
parseInt("110",10)==NaN;//return false

Because NaN and itself do not want to wait, this is quite special. The way to judge NaN is isNaN() ;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template