typeof Operator

Last updated: 2026-09-09

typeof Operator

typeof returns a string naming the type of its operand — the quickest way to inspect a value. It is a unary operator written as typeof x or typeof(x). Note the result is a string: typeof 42 is "number", not Number itself.

CategoryOperators
KindUnary operator
ES versionES1 (1997)
OperandsOne
Undeclared namesYes (returns "undefined" instead of throwing)

📝 Syntax

typeof operand
typeof(operand)

⚙️ Parameters

操作数Any value or variable; even an undeclared name is safe and yields "undefined".

Returns:A type string: "undefined", "boolean", "number", "bigint", "string", "symbol", "function" or "object".

Mutates the original:No (returns a new value)

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

number
string
boolean
undefined
object
object
object
function
⚠️ Warning typeof null returns "object" — a bug frozen into the language since 1995, when null carried the object type tag. To test for null compare directly: x === null.
💡 Tip typeof cannot tell an array from a plain object (both are "object"); use Array.isArray(x) instead.

🌐 Browser support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
typeof v1 v12 v1 v1 v1
Supported by all modern browsers
More case studies coming soon — check back later.

📚 Related Tutorials

❓ FAQ

QWhy is typeof null "object"?
AIt is an artifact of the very first implementation: values were stored in 32 bits with a low type tag, and null is all zeros, which landed in the object tag range. Too much early web code depended on it to fix during standardization, so test null with x === null.
QCan typeof distinguish an array from an object?
ANo — arrays, plain objects, dates and regular expressions all report "object". Use Array.isArray(x), x instanceof Date, or Object.prototype.toString.call(x) to tell them apart.
QHow do I test a variable that may not be declared?
Atypeof someVar !== "undefined" is the only safe form. Writing if (someVar) throws a ReferenceError when the name was never declared, whereas typeof simply returns "undefined" and execution continues.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏