console.log(({
title: "The Three Musketeers",
author: "Alexandre Dumas",
price: "$49"
}).toString());
It outputs an Object as [object Object], even though I am calling .toString() on it. Can anyone please explain why this happens?
Because for have built a JavaScript object that you are attempt to convert to a string. You are attempting to convert the entire object to a string, which can't (really) be done. As such, you simply get text that says "Hey, we've got an object here".
If however, you were to run .toString() on a property of that object (which is probably your intent), you would get a string representation of that property. This can be done by accessing the proeprty with the dot notation just before calling .toString(), as follows:
console.log(({
title: "The Three Musketeers",
author: "Alexandre Dumas",
price: "$49"
}).title.toString());
If you're looking for a JSON string representation of the object, look into JSON.stringify()
toString, so it uses the one from object.