Object.prototype.toString

Returns a string representation of an object.

Syntax

toString()

Return value

A string representation of the object.

Examples

{}.toString()
"[object Object]"
let vehicle = {
  speed: 10,
  unit: "km/h",
  [Symbol.toStringTag]: "Vehicle",
  toString() {
    return `${this[Symbol.toStringTag]} ${this.speed} ${this.unit}`
  }
}
vehicle.toString()
"Vehicle 10 km/h"