Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 18:49:212546browse
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() ;
Statement:
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