| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/typeof | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
typeof .
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 operand
typeof . JavaScript .
| Type | Result |
|---|---|
| Undefined | "undefined" |
| Null | "object" ( ) |
| Boolean | "boolean" |
| Number | "number" |
| BigInt | "bigint" |
| String | "string" |
| Symbol | "symbol" |
| Function (ECMA-262 [[Call]] ) | "function" |
"object" |
. .
// Numbers
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"; // Number
typeof Number("shoe") === "number"; //
typeof 42n === "bigint";
// Strings
typeof "" === "string";
typeof "bla" === "string";
typeof `template literal` === "string";
typeof "1" === "string"; // typeof string
typeof typeof 1 === "string"; // typeof
typeof String(1) === "string"; // String , toString()
// Booleans
typeof true === "boolean";
typeof false === "boolean";
typeof Boolean(1) === "boolean"; // Boolean() truthy/falsy
typeof !!1 === "boolean"; // ! ( ) Boolean()
// Symbols
typeof Symbol() === "symbol";
typeof Symbol("foo") === "symbol";
typeof Symbol.iterator === "symbol";
// Undefined
typeof undefined === "undefined";
typeof declaredButUndefinedVariable === "undefined";
typeof undeclaredVariable === "undefined";
// Objects
typeof { a: 1 } === "object";
// Array.isArray Object.prototype.toString.call
typeof [1, 2, 4] === "object";
typeof new Date() === "object";
typeof /regex/ === "object";
// , , .
typeof new Boolean(true) === "object";
typeof new Number(1) === "object";
typeof new String("abc") === "object";
// Functions
typeof function () {} === "function";
typeof class C {} === "function";
typeof Math.sin === "function";
typeof null// JavaScript
typeof null === "object";
JavaScript , JavaScript . 0. null Null pointer( 0x00) . null 0 , typeof object . ( )
ECMAScript (opt-in ) . . typeof null === 'null'.
new ("object" "function") . , Function .
const str = new String("String");
const num = new Number(100);
typeof str; // "object"
typeof num; // "object"
const func = new Function();
typeof func; // "function"
// .
const someData = 99;
typeof someData + " foo"; // "number foo"
typeof (someData + " foo"); // "string"
typeof . typeof "undefined" .
typeof undeclaredVariable; // "undefined"
(let const, class
) typeof ReferenceError . (TDZ) , .
typeof newLetVariable; // ReferenceError
typeof newConstVariable; // ReferenceError
typeof newClass; // ReferenceError
let newLetVariable;
const newConstVariable = "hello";
class newClass {}
undefined document.all
.
typeof document.all === "undefined";
document.all falsy undefined , undefined . document.all "undefined" ECMAScript " (willful violation)" .
typeof , . , typeof [] "object", typeof new Date(), typeof /abc/ .
type(value) . typeof , (, ) .
function type(value) {
if (value === null) {
return "null";
}
const baseType = typeof value;
//
if (!["object", "function"].includes(baseType)) {
return baseType;
}
// Symbol.toStringTag " " .
// Object.prototype.toString() .
const tag = value[Symbol.toStringTag];
if (typeof tag === "string") {
return tag;
}
// "class" .
if (
baseType === "function" &&
Function.prototype.toString.call(value).startsWith("class")
) {
return "class";
}
// ; : `Array`, `GeneratorFunction`,
// `Number`, `String`, `Boolean`, `MyCustomClass`
const className = value.constructor.name;
if (typeof className === "string" && className !== "") {
return className;
}
// ,
// .
return baseType;
}
ReferenceError typeof nonExistentVar === "undefined" . .
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-typeof-operator |
This page was last modified on 2026 7 15 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 |