Reputation: 207
I read JavaScript book called "JavaScript: The Definitive Guide" and I see the following. "The Date type represents dates and times and supports rudimentary date arithmetic."
There is no "Date" in the list of primitive and object types, why "Date" is considered as type if it's just an object and in JavaScript if I am correct it's not possible to create our own types.
Is Date considered type in JavaScript?
Upvotes: 2
Views: 2985
Reputation: 147453
There is no "Date Type", ECMASCript Types are:
Note that the value returned by typeof does not necessarily match the Type of the value, e.g.
typeof null
returns "object"typeof someFun
returns "function", where someFn is a an object that implements an internal call method (i.e. is a function)ECMAScript has a built–in Date object that is a function that can also be called as a constructor. So:
typeof Date
returns "function" even though it's an Object Type, whereas using the typeof operator on a Date instance:
typeof new Date()
returns "object", as it's also an Object Type. The term "Date object" is commonly used to refer to a Date instance, and "Date constructor" to refer to the built–in Date object/function/constructor.
Upvotes: 6
Reputation: 5428
To illustrate @aravind's point:
console.log(typeof Date());
console.log(typeof new Date());
Upvotes: 0