| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | [Back] [Original] |
Get to know MDN better
const map = new Map();
console.log(map.toString());
// : "[object Map]"
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
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() valueOf() TypeError
Dog
class Dog {
constructor(name, breed, color, sex) {
this.name = name;
this.breed = breed;
this.color = color;
this.sex = sex;
}
}
toString() Object
const theDog = new Dog("Gabby", "Lab", "chocolate", "female");
theDog.toString(); // "[object Object]"
`${theDog}`; // "[object Object]"
toString() name, breed, color, sex
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()
const theDog = new Dog("Gabby", "Lab", "chocolate", "female");
`${theDog}`; // "Dog Gabby is a female chocolate Lab"
toString() ()
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
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 |
Objectassign()create()defineProperties()defineProperty()entries()freeze()fromEntries()getOwnPropertyDescriptor()getOwnPropertyDescriptors()getOwnPropertyNames()getOwnPropertySymbols()getPrototypeOf()groupBy()hasOwn()is()isExtensible()isFrozen()isSealed()keys()preventExtensions()seal()setPrototypeOf()values()Object/Function| Web Proxy Viewer | New URL | Original Page |