Course contentsShow
← JavaScript
Lesson 1609 of 2,72335. Standard Library and Built-insFree lesson

The Date Constructor with No Arguments

Create a Date object representing the current moment using new Date() and understand its internal representation.

The Date Constructor with No Arguments

What you'll learn: How to capture the current moment in time using JavaScript's Date constructor without any arguments.

When you call new Date() without passing any arguments, JavaScript creates a Date object that represents right now — the exact moment the code executes.

The Current Moment in Code

Think of new Date() as taking a snapshot of time. The moment you call it, JavaScript reaches out to your computer's clock and captures the current date and time down to the millisecond.

const now = new Date();
console.log(now);
// Output (example): 2024-01-15T14:32:07.823Z

Each time you call new Date(), you get a fresh timestamp:

const time1 = new Date();
// ... some code runs ...
const time2 = new Date();

console.log(time1); // Earlier time
console.log(time2); // Later time (even if just milliseconds)

Internal Representation

Behind the scenes, JavaScript stores dates as a single number: the number of milliseconds since midnight on January 1, 1970, UTC (often called the Unix epoch). This makes dates easy to compare and calculate with, even though you see them formatted as human-readable strings when logged.

const now = new Date();
console.log(now.valueOf()); 
// Output (example): 1705329127823
// That's over 1.7 trillion milliseconds since 1970!

This internal millisecond timestamp is what makes Date objects so powerful for tracking time, measuring durations, and scheduling events.

Key Takeaway: new Date() with no arguments creates a Date object representing the current moment, stored internally as milliseconds since January 1, 1970, UTC.