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

Object.prototype.toString() - 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

Object.prototype.toString()

Baseline Widely available

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

Object toString() object . .

In this article

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"

js
toString();

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

.

toString . toString . .

, 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 ) .

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() . toString() .

Dog Dog theDog :

js
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 :

js
theDog.toString(); // returns [object Object]

toString() dogToString() . name, breed, color, sex "property = value;" .

js
Dog.prototype.toString = function dogToString() {
  var ret =
    "Dog " +
    this.name +
    " is a " +
    this.sex +
    " " +
    this.color +
    " " +
    this.breed;
  return ret;
};

theDog JavaScript dogToString() :

js
"Dog Gabby is a female chocolate Lab";

toString()

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

js
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


Web Proxy Viewer  |  New URL  |  Original Page