[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag [Back]  [Original]

Symbol.toStringTag - 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

Symbol.toStringTag

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 4.

Symbol.toStringTag @@toStringTag . Object.prototype.toString() this .

In this article

class ValidatorClass {
  get [Symbol.toStringTag]() {
    return "Validator";
  }
}

console.log(Object.prototype.toString.call(new ValidatorClass()));
// Expected output: "[object Validator]"

@@toStringTag.

Property attributes of Symbol.toStringTag

Symbol.toStringTag toString() . Object.prototype.toString()() .

js
Object.prototype.toString.call("foo"); // "[object String]"
Object.prototype.toString.call([1, 2]); // "[object Array]"
Object.prototype.toString.call(3); // "[object Number]"
Object.prototype.toString.call(true); // "[object Boolean]"
Object.prototype.toString.call(undefined); // "[object Undefined]"
Object.prototype.toString.call(null); // "[object Null]"
// ... and more

toStringTag

@@toStringTag . @@toStringTag , , Iterator .

Promise , Constructor.prototype @@toStringTag . Math JSON . toString (: Intl.Locale), @@toStringTag Object.prototype.toString .

js
Object.prototype.toString.call(new Map()); // "[object Map]"
Object.prototype.toString.call(function* () {}); // "[object GeneratorFunction]"
Object.prototype.toString.call(Promise.resolve()); // "[object Promise]"
// ... and more

toStringTag

JavaScript "Object" .

js
class ValidatorClass {}

Object.prototype.toString.call(new ValidatorClass()); // "[object Object]"

toStringTag .

js
class ValidatorClass {
  get [Symbol.toStringTag]() {
    return "Validator";
  }
}

Object.prototype.toString.call(new ValidatorClass()); // "[object Validator]"

DOM toStringTag

2020 WebIDL DOM Symbol.toStringTag . , HTMLButtonElement Symbol.toStringTag .

js
const test = document.createElement("button");
test.toString(); // "[object HTMLButtonElement]"
test[Symbol.toStringTag]; // "HTMLButtonElement"

Specification
ECMAScript 2027 LanguageSpecification
# sec-symbol.tostringtag


Web Proxy Viewer  |  New URL  |  Original Page