JavaScript: The connection between the now function and constructor on Date
1 min read

JavaScript: The connection between the now function and constructor on Date

In JavaScript, contrary to the expectation, Date.now() returns a number instead of a Date object as expected in other programming languages. This returned number represents the milliseconds passed since January 1, 1970.

Luckily, one of the constructors on the Date accepts these milliseconds, and a Date could be constructed.

const now = Date.now();

const nowDate = new Date(now);

console.log(nowDate); // prints Date