| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/toString | [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.
Object toString() object . .
function Dog(name) {
this.name = name;
}
const dog1 = new Dog("Gabby");
Dog.prototype.toString = function dogToString() {
return `${this.name}`;
};
console.log(dog1.toString());
// Expected output: "Gabby"
toString();
toString() . Object . , Number.prototype.toString() BigInt.prototype.toString() (radix) .
.
, valueOf() . valueOf() , valueOf() toString() . , +[1] 1 , +[1] toString() "1" .
Object.prototype (null- ) toString() . toString() , . @@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() . toString() . toString() .
Dog Dog theDog :
function Dog(name, breed, color, sex) {
this.name = name;
this.breed = breed;
this.color = color;
this.sex = sex;
}
theDog = new Dog("Gabby", "Lab", "chocolate", "female");
toString() Object :
theDog.toString(); // returns [object Object]
toString() dogToString() . name, breed, color, sex "property = value;" .
Dog.prototype.toString = function dogToString() {
var ret =
"Dog " +
this.name +
" is a " +
this.sex +
" " +
this.color +
" " +
this.breed;
return ret;
};
theDog JavaScript dogToString() :
"Dog Gabby is a female chocolate Lab";
toString() toString() . Object.prototype.toString() Function.prototype.call() Function.prototype.apply() thisArg .
var toString = Object.prototype.toString;
toString.call(new Date()); // [object Date]
toString.call(new String()); // [object String]
toString.call(Math); // [object Math]
// Since JavaScript 1.8.5
toString.call(undefined); // [object Undefined]
toString.call(null); // [object Null]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.prototype.tostring |
Object.prototype.toSource()Object.prototype.valueOf()Number.prototype.toString()Symbol.toPrimitiveThis page was last modified on 2026 7 15 by MDN contributors.
ObjectObject.assign()Object.create()Object.defineProperties()Object.defineProperty()Object.entries()Object.freeze()Object.fromEntries()Object.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptors()Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.getPrototypeOf()Object.groupBy()Object.hasOwn()Object.is()Object.isExtensible()Object.isFrozen()Object.isSealed()Object.keys()Object.preventExtensions()Object.seal()setPrototypeOf()Object.values()Object.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()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 |