Take the 2-minute tour ×

I have the following code

var d = new Date();
Object.prototype.toString(d); //outputs  "[object Object]"
Object.prototype.toString.apply(d); //outputs "[object Date]"

Why is this difference and what's going on?


d.toString() // outputs "Tue Nov 06 2012 ..."

So from where does the Date in "[object Date]" comes from. Is it the native code of the browser that do the trick?

share|improve this question
add comment

3 Answers


converts Object.prototype to string and ignores its argument. In


d gets passed as this to the ToString method (as if d.toString() with toString referring to Object.prototype.toString was called), which is what the method respects.

See Function#apply and Object#toString

share|improve this answer
But d.toString() is giving entirely different result. right? –  suhair Nov 6 '12 at 6:49
Yes, because in that case you are calling Date.prototype.toString not Object.prototype.toString (i.e. Date instances inherit a different toString method). –  RobG Nov 6 '12 at 6:59
add comment

Another explanation is that Object.prototype.toString operates on its this object. A function's this is set by how you call it so when you do:


the toString function's this is the Object.prototype object. When you call it as:


its this is the object referenced by d (a Date object).

share|improve this answer
add comment

The parameter is ignored in the first call. You are calling the toString method on the Object.prototype object, basically the same as:

{}.toString(); //outputs  "[object Object]"

In the second call you are calling the toString method for Object but applying the Date object as its context. The method returns the type of the object as a string, compared the toString method of the Date object which would instead return the value of the Date object as a string.

share|improve this answer
add comment

Your Answer


