Returns a string representation of an object.
toString()
A string representation of the object.
{}.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"