Labs ICT
โญ Pro Login

Typeof

1 min read | JavaScript Tutorial
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

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(){});

Arrays also return "object". Use Array.isArray() to check for arrays specifically.

๐Ÿงช Quick Quiz

What does typeof 'hello' return?