This post will discuss how to determine whether a string is numeric in JavaScript.

1. Using isNaN() method

The recommended solution is to use the isNaN() method, which tests a value for NaN (Not a Number). To illustrate, consider the following code, where the isNumeric() returns true when the given string is a number and false otherwise.

2. Using Number() function

A simple and fairly efficient solution to convert the given string to a numerical value is using Number as a function, which returns NaN if it cannot be converted into a number.

This is demonstrated below, where we cast the return value of the Number() function to be boolean using !!expr.

That’s all about checking if a string is numeric in JavaScript.