toString
methodlet user = {
name: "John",
age: 30,
toString() {
return `{name1: "${this.name}", age1: ${this.age}}`;
}
};
document.write(user);
// document.write(JSON.stringify(user));
The code above will produce the following result:{name1: "John", age1: 30}