by @kodeazy
How to check a variable is number or string in javascript?
- To check whether a variable is string or not we use
isNaN
function. - Below is the syntax.
isNaN('-234')
.- returns
true
if the data inside the above function is not anumber
else returnsfalse
. -
Below is the sample example.
var numberOrString=isNaN('-234'); console.log(numberOrString);
Output:
false