Check if a string is a valid number in JavaScript

You can check if a string is a valid number using the isNaN() function.

Example:

javascript
let isNumber_0 = !isNaN('47');    // true
let isNumber_1 = !isNaN('47.25'); // true
let isNumber_2 = !isNaN('47,25'); // false
let isNumber_3 = !isNaN('Erik');  // false
let isNumber_4 = !isNaN('');      // true

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.