[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/toString [Back]  [Original]

Object.prototype.toString() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Object.prototype.toString()

Baseline

20157

toString() Object

const map = new Map();

console.log(map.toString());
// : "[object Map]"

js
toString()

toString() Object toString() Number.prototype.toString() BigInt.prototype.toString() radix

JavaScript toString toString JavaScript toString

valueOf() valueOf() valueOf() toString() +[1] 1 toString() "1"

Object.prototype null toString() toString() [Symbol.toPrimitive]() valueOf toString

Object.prototype.toString() null undefined Function.prototype.call() Function.prototype.apply() thisArg

js
const arr = [1, 2, 3];

arr.toString(); // "1,2,3"
Object.prototype.toString.call(arr); // "[object Array]"

Object.prototype.toString() "[object Type]" Type Symbol.toStringTag Type Map Symbol Symbol.toStringTag ES6 Symbol.toStringTag

arguments "[object Arguments]" Symbol.toStringTag "[object Object]"

Object.prototype.toString() null undefined [object Null] [object Undefined]

toString

toString() toString() valueOf() TypeError

Dog

js
class Dog {
  constructor(name, breed, color, sex) {
    this.name = name;
    this.breed = breed;
    this.color = color;
    this.sex = sex;
  }
}

toString() Object

js
const theDog = new Dog("Gabby", "Lab", "chocolate", "female");

theDog.toString(); // "[object Object]"
`${theDog}`; // "[object Object]"

toString() name, breed, color, sex

js
class Dog {
  constructor(name, breed, color, sex) {
    this.name = name;
    this.breed = breed;
    this.color = color;
    this.sex = sex;
  }
  toString() {
    return `Dog ${this.name} is a ${this.sex} ${this.color} ${this.breed}`;
  }
}

Dog JavaScript toString()

js
const theDog = new Dog("Gabby", "Lab", "chocolate", "female");

`${theDog}`; // "Dog Gabby is a female chocolate Lab"

toString()

toString() ()

js
const toString = Object.prototype.toString;

toString.call(new Date()); // [object Date]
toString.call(new String()); // [object String]
// Math  Symbol.toStringTag
toString.call(Math); // [object Math]

toString.call(undefined); // [object Undefined]
toString.call(null); // [object Null]

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

js
const myDate = new Date();
Object.prototype.toString.call(myDate); // [object Date]

myDate[Symbol.toStringTag] = "myDate";
Object.prototype.toString.call(myDate); // [object myDate]

Date.prototype[Symbol.toStringTag] = "prototype polluted";
Object.prototype.toString.call(new Date()); // [object prototype polluted]

ECMAScript 2027 LanguageSpecification
# sec-object.prototype.tostring


Web Proxy Viewer  |  New URL  |  Original Page