Buy Me A Coffee 😇

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().

#javascript
#string
✍️ BroJenuel
Mar. 08, 2023. 2:05 PM

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

If you enjoy this article and would like to show your support, you can easily do so by buying me a coffee. Your contribution is greatly appreciated!

Buy Me a Coffee at https://www.buymeacoffee.com
@ BroJenuel