xxxxxxxxxx
// solution 1: Override the toString() method directly in your Object
let obj={Name: 'Bob',Age='35',
toString(){
return JSON.stringify(this);
}};
console.log(obj.toString());
// output: {"Name":"Bob","Age":35}
// solution 2(preferred_option -> but there's gr8er risk of bugs'): Overriding Object.prototype.toString with your own function.
Object.prototype.toString=function(){
return JSON.stringify(this);
}
let obj={Name: 'Bob',Age='35'};
console.log(obj.toString());
// output: {"Name":"Bob","Age":35}