ECMAScript Language Specification
According to the ECMAScript specification (on which Javascript is based):
When Date is called as a function rather than as a constructor, it
returns a String representing the current time (UTC).
NOTE The function call Date(…) is not equivalent to the object
creation expression new Date(…) with the same arguments.
Reference: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.2
Calling Constructor vs Calling Function
You need the new
because you are creating a new Date
object.
Calling simply Date() , means calling a function that returns the Date() as a string.
See: http://www.javascripture.com/Date
Date() : String
Returns a string representation of the current date and time.
In the case of other types such as Array or Error, the functions are factory functions that create a new object and return them.
See:
- http://www.javascripture.com/Error
http://www.javascripture.com/Array
Error(message : String) : Error
Creates a new Error with the specified message that describes the error.
new Error(message : String) : Error
Same as Error(message)