The Symbol.toStringTag static data property represents the well-known symbol used in the creation of the default string description of an object. It is accessed internally by the Object.prototype.toString() method.

Try it


The well-known symbol @@toStringTag.

Property attributes of Symbol.toStringTag
Writable no
Enumerable no
Configurable no


Default tags

Some values do not have Symbol.toStringTag, but have special toString() representations. For a complete list, see Object.prototype.toString()."foo"); // "[object String]"[1, 2]); // "[object Array]"; // "[object Number]"; // "[object Boolean]"; // "[object Undefined]"; // "[object Null]"
// ... and more

Built-in toStringTag symbols

Most built-in objects provide their own @@toStringTag property. All built-in objects' @@toStringTag property is not writable, not enumerable, and configurable. Map()); // "[object Map]"* () {}); // "[object GeneratorFunction]"; // "[object Promise]"
// ... and more

Custom tag with toStringTag

When creating your own class, JavaScript defaults to the "Object" tag:

class ValidatorClass {} ValidatorClass()); // "[object Object]"

Now, with the help of toStringTag, you are able to set your own custom tag:

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

toStringTag available on all DOM prototype objects

Due to a WebIDL spec change in mid-2020, browsers are adding a Symbol.toStringTag property to all DOM prototype objects. For example, to access the Symbol.toStringTag property on HTMLButtonElement:

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


ECMAScript Language Specification
# sec-symbol.tostringtag

Browser compatibility

BCD tables only load in the browser

See also