typeof Operator
EasyIn plain terms
typeof returns a string indicating the type: "string", "number", "boolean", "undefined", "object", "function", "symbol", "bigint". Note: typeof null is "object" (historical bug).
What you need to know
- •Returns string type name
- •typeof null is "object"
- •Use for runtime type checks
Try it yourself
Copy the code below and run it in your browser console or a code editor:
typeof 42; // "number"
typeof 'hello'; // "string"
typeof true; // "boolean"
typeof undefined; // "undefined"
typeof null; // "object" (bug!)
typeof {}; // "object"
typeof []; // "object"
typeof function(){};// "function"
typeof Symbol(); // "symbol"Learn more
Dive deeper with these trusted resources: