Interview Question

What is typeof operator?

typeof gives a type category, but null and arrays need separate checks.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

The typeof operator returns a string that describes the type category of its operand. • It reports function for callable objects. • It reports object for ordinary objects and also for null because of legacy behavior. • Use a direct null check or Array.isArray when those distinctions matter.

Example

Code
console.log(typeof null);
console.log(typeof (() => {}));
console.log(Array.isArray([]));
Output
object
function
true

Quick Revision

typeof gives a type category, but null and arrays need separate checks.