The typeof Operator
typeof is a unary operator that tells you the type of a value. It returns a string like "string", "number", "boolean", "object", "undefined", "function", or "symbol".
One famous quirk: typeof null returns "object". This is a bug from the early days of JavaScript that can't be fixed without breaking existing code.
console.log(typeof "Hello");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof null);
console.log(typeof {});
console.log(typeof []);
console.log(typeof function(){});
Try it Yourself โ
Arrays also return "object". Use Array.isArray() to check for arrays specifically.