typeof (JavaScript)
typeof is an operator that returns a string naming the type of a value, such as "number", "string", or "object". It is used to check what kind of data you have.
JavaScript
typeof is handy for guarding code against unexpected input. Note its two famous quirks: typeof null is "object" (a long-standing bug), and typeof an array is also "object".
Use Array.isArray() to specifically detect arrays.
Syntax
typeof valueExamples
JavaScript
console.log(typeof 42);
console.log(typeof "hi");
console.log(typeof null);Output:
number
string
object