What Javascript language rule leads to the following conversion weirdness?
new Date() - 2 => number
new Date() * 2 => number
new Date() / 2 => number
but
new Date() + 2 => string
I had thought that the + operator would use the valueOf() method of the Date object to convert it to a number. Like in the following example:
{valueOf: function() {return 1;}} + 2 => number
What is different in the case of a Date?
After studying the Javascript spec, there is indeed a special case for Date objects in the context of the addition operator:
http://ecma-international.org/ecma-262/5.1/#sec-11.6.1
Conversion of a Date object is handled differently than for other objects:
I think I understand the motivation, but as a language rule, this feels quite ugly.