The second "Object" is actually the class of the object:
"b" + (new Event('hello')) // "b[object Event]"
So there is some logic to it, it's just not the best logic there could be. Would it make more sense to JSON-stringify it? Yes, hella yes. But the problem is, JavaScript actually came first, not JSON, the object to string casting is a core part of the language, and JS is completely backwards-compatible (it kinda has to, a breaking change would potentially break the entire web). So, unfortunately, there is no way to change that now.
I tried this with class Foobar{}; console.log(""+new Foobar()) in Firefox dev console, but that just gave me [object Object]. So it might be the built-in type of the object.
5
u/DeeSnow97 Aug 26 '20
The second "Object" is actually the class of the object:
So there is some logic to it, it's just not the best logic there could be. Would it make more sense to JSON-stringify it? Yes, hella yes. But the problem is, JavaScript actually came first, not JSON, the object to string casting is a core part of the language, and JS is completely backwards-compatible (it kinda has to, a breaking change would potentially break the entire web). So, unfortunately, there is no way to change that now.