Check String If its a number

When checking string if its a number, there are a lot of ways you can check a string if its a number. You can use regex, isNaN() function, or a plus operator, or parseInt.

But the best function that we can use is a function called Number().

The Numbe…


This content originally appeared on DEV Community and was authored by Jenuel Oras Ganawed

When checking string if its a number, there are a lot of ways you can check a string if its a number. You can use regex, isNaN() function, or a plus operator, or parseInt.

But the best function that we can use is a function called Number().

The Number() function converts the argument to a number representing the object’s value. If it fails to convert the value to a number, it returns NaN.

We can use it with strings also to check whether a given string is a number or not.

console.log(Number('195')) // 195
console.log(Number('boo')) // Nan


This content originally appeared on DEV Community and was authored by Jenuel Oras Ganawed


Print Share Comment Cite Upload Translate Updates
APA

Jenuel Oras Ganawed | Sciencx (2022-02-22T00:43:53+00:00) Check String If its a number. Retrieved from https://www.scien.cx/2022/02/22/check-string-if-its-a-number/

MLA
" » Check String If its a number." Jenuel Oras Ganawed | Sciencx - Tuesday February 22, 2022, https://www.scien.cx/2022/02/22/check-string-if-its-a-number/
HARVARD
Jenuel Oras Ganawed | Sciencx Tuesday February 22, 2022 » Check String If its a number., viewed ,<https://www.scien.cx/2022/02/22/check-string-if-its-a-number/>
VANCOUVER
Jenuel Oras Ganawed | Sciencx - » Check String If its a number. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/22/check-string-if-its-a-number/
CHICAGO
" » Check String If its a number." Jenuel Oras Ganawed | Sciencx - Accessed . https://www.scien.cx/2022/02/22/check-string-if-its-a-number/
IEEE
" » Check String If its a number." Jenuel Oras Ganawed | Sciencx [Online]. Available: https://www.scien.cx/2022/02/22/check-string-if-its-a-number/. [Accessed: ]
rf:citation
» Check String If its a number | Jenuel Oras Ganawed | Sciencx | https://www.scien.cx/2022/02/22/check-string-if-its-a-number/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.