[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/typeof [Back]  [Original]

typeof - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

typeof

Baseline Widely available

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)

In this article

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"

js
// 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";

null

js
typeof null === "object"; //  JavaScript 

JavaScript , JavaScript 0. null NULL ( 0x00) . , null 0 , typeof . ()

ECMAScript ( opt-in ). typeof null === 'null'

(Regular expressions)

(need reference to say which).

js
typeof /s/ === "function"; // Chrome 1-12 ... //  ECMAScript 5.1 (:  Chrome  'object')
typeof /s/ === "object"; // Firefox 5+ ...    //  ECMAScript 5.1

(quirks)

Internet Explorer alert

IE 6, 7 8, typeof alert === 'object'

IE , ,

Specification
ECMAScript 2027 LanguageSpecification
# sec-typeof-operator


Web Proxy Viewer  |  New URL  |  Original Page