Is there any expression where by an object\'s toString method is implicitly called overriding its valueOf method?
In the examples below, valueOf is alw
The + operator on Date objects uses toString not valueOf. Also if valueOf returns a non-primitive value then the toString method is called next. (JavaScript - The definitive guide, section 3.14) Using your example:
var result = "4" + {
toString: function () {
return "4";
},
valueOf: function () {
return this; // returning an object, not a primitive
}
};
Result is now 44.