Scenario
I was toying with some Javascript object programming, when I wrote down the following code (demo here):
var o = {
"key":1,
"value": 1234,
toString: function(){
var res = this.key + ";" + this.value;
return res;
}
};
var p = {
"key":2,
"value": 5678
};
document.write(o);
document.write("</br>");
document.write(p);
As you can see, having a toString() method let the o object to be displayed without calling the toString() method, while the p object is displayed as... as what?
QUESTIONS
Is the
toStringliteral a kind of default name for objects representation? Or what else?What does the
[object Object]notation mean?