I'm sorry but the new Date()
is not returning an object as I understand an object.
From the MDN article on Date
constructor :
When no parameters are provided, the newly-created Date object represents the current date and time as of the time of instantiation.
(emphasis added)
All right then, where is the object there :
const date1 = new Date();
console.log(date1);
// returns Wed Jan 27 2021 15:45:31 GMT+0100
An object would be
{date: "Wed Jan 27 2021 15:45:31 GMT+0100")}
But it looks more like a string, BUT we can't manipulate it like a string, since :
const date1 = new Date();
console.log(date1[0]); // expecting "W"
// returns undefined
I know how to manipulate this special format with the different time methods but this has always been a mystery for me.
What is this format ?
Another Type ?
And why there is no object returned by the constructor new Date()
?