by @kodeazy
How to check a variable is a number or String in javascript?
- I had a variables in javascript with
var x="5"
andvar y=5
. - To identify above variables is a
number
type orstring
type we usetypeof
operator. -
Below is an example of identifying the
type
.var x="5"; var y=5; console.log(typeof x);// returns String as output console.log(typeof y);//returns number as output
Output
string number