Javascript: Variable Type

(Last Updated On: )

If you want to test a variable is a type.

  1. var test_type = Object.prototype.toString.call(variable);
  2. //If it is a string type
  3. test_type.includes("String")
  4. //If it is a numeric type
  5. test_type.includes("Number")
  6.