An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
February 22, 2022 12:43 am GMT
Original Link: https://dev.to/brojenuel/check-string-if-its-a-number-4e5n
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 Number()
function converts the argument to a number representing the objects 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')) // 195console.log(Number('boo')) // Nan
Original Link: https://dev.to/brojenuel/check-string-if-its-a-number-4e5n
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To