by @kodeazy

How to check a variable is a number or String in javascript?

Home » javascript » How to check a variable is a number or String in javascript?
  • I had a variables in javascript with var x="5" and var y=5.
  • To identify above variables is a number type or string type we use typeof 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