| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/typeof | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.
typeof , (unevaluated)
| : | JavaScript 1.1 |
| ECMA : | ECMA-262 ( ECMA-357 for E4X objects) |
typeof :
typeof operand
operand
typeof :
| Undefined | "undefined" |
| Null | "object" |
| Boolean | "boolean" |
| Number | "number" |
| String | "string" |
| ( JS ) | |
| Function ( ECMA-262 [[Call]]) | "function" |
| E4X XML | "xml" |
| E4X XMLList | "xml" |
"object" |
// Numbers
typeof 37 === "number";
typeof 3.14 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; // "Not-A-Number"
typeof Number(1) === "number"; // !
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof typeof 1 === "string"; // typeof
typeof String("abc") === "string"; // !
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean(true) === "boolean"; // !
// Undefined
typeof undefined === "undefined";
typeof blabla === "undefined"; // undefined
// Objects
typeof { a: 1 } === "object";
typeof [1, 2, 4] === "object"; // Array.isArray Object.prototype.toString.call
typeof new Date() === "object";
typeof new Boolean(true) === "object"; // !
typeof new Number(1) === "object"; // !
typeof new String("abc") === "object"; // !
// Functions
typeof function () {} === "function";
typeof Math.sin === "function";
nulltypeof null === "object"; // JavaScript
JavaScript , JavaScript 0. null NULL ( 0x00) . , null 0 , typeof . ()
ECMAScript ( opt-in ). typeof null === 'null'
(need reference to say which).
typeof /s/ === "function"; // Chrome 1-12 ... // ECMAScript 5.1 (: Chrome 'object')
typeof /s/ === "object"; // Firefox 5+ ... // ECMAScript 5.1
IE 6, 7 8, typeof alert === 'object'
IE , ,
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-typeof-operator |
This page was last modified on 2025716 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |