To check if a string is a number JavaScript, do this:
!isNaN(string)
.Here's how you do it:
const twoIsNumber = !isNaN('2');
const twoPointFiveIsNumber = !isNaN('2.5');
const helloWorldIsNumber = !isNaN('Hello World!');
console.log(twoIsNumber); // true
console.log(twoPointFiveIsNumber); // true
console.log(helloWorldIsNumber); // false