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

typeof - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

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 2015 ..

typeof , .

In this article

console.log(typeof 42);
// Expected output: "number"

console.log(typeof "blubber");
// Expected output: "string"

console.log(typeof true);
// Expected output: "boolean"

console.log(typeof undeclaredVariable);
// Expected output: "undefined"

typeof:

typeof operand

operand , , .

typeof. JavaScript.

Type Result
Undefined "undefined"
Null "object" ( )
Boolean "boolean"
Number "number"
String "string"
Symbol ( ECMAScript 2015) "symbol"
Host object ( JS )
Function object ( [[Call]] ECMA-262) "function"
"object"

js
// 
typeof 37 === "number";
typeof 3.14 === "number";
typeof 42 === "number";
typeof Math.LN2 === "number";
typeof Infinity === "number";
typeof NaN === "number"; //   ,   "Not-A-Number" ( )
typeof Number(1) === "number"; //     !

// 
typeof "" === "string";
typeof "bla" === "string";
typeof "1" === "string"; //  ,         
typeof typeof 1 === "string"; // typeof      
typeof String("abc") === "string"; //     !

// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean(true) === "boolean"; //     !

// 
typeof Symbol() === "symbol";
typeof Symbol("foo") === "symbol";
typeof Symbol.iterator === "symbol";

// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";

// 
typeof { a: 1 } === "object";

//  Array.isArray  Object.prototype.toString.call
//      
typeof [1, 2, 4] === "object";

typeof new Date() === "object";

//        .  !
typeof new Boolean(true) === "object";
typeof new Number(1) === "object";
typeof new String("abc") === "object";

// 
typeof function () {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";

null

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

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

ECMAScript ( ), . , typeof null === 'null'.

new

js
//  -,    'new',    'object'
var str = new String("String");
var num = new Number(100);

typeof str; //  'object'
typeof num; //  'object'

//      Function

var func = new Function();

typeof func; //  'function'

.

js
typeof /s/ === "function"; // Chrome 1-12   ECMAScript 5.1
typeof /s/ === "object"; // Firefox 5+   ECMAScript 5.1

,

ECMAScript 2015, , typeof , . let and const . , let const, typeof , , ReferenceError. , typeof 'undefined'. " ", . .

js
typeof undeclaredVariable === "undefined";
typeof newLetVariable;
let newLetVariable; // ReferenceError
typeof newConstVariable;
const newConstVariable = "hello"; // ReferenceError

host- document.all, Undefined.

js
typeof document.all === "undefined";

, . , document.all undefined .

Specification
ECMAScript 2027 LanguageSpecification
# sec-typeof-operator

IE-

IE 6, 7 8 host- , . :

js
typeof alert === "object";


Web Proxy Viewer  |  New URL  |  Original Page