Skip to solution
hardFrontend

How does the Temporal API fix JavaScript Date — Instant, PlainDate and ZonedDateTime?

437 views
01

Understand the problem

Question presented to candidate: "If you write const d = new Date(2024, 0, 31); d.setMonth(1);, does that genuinely change d in place, and what does d actually become? How would the Temporal equivalent behave differently?"

What a strong answer should cover:

  • 📌 Interview term: the real, direct answer to the prompt — verified directly, in a real, current browser (Temporal is not yet available in Node, confirmed directly): the legacy Date object is genuinely mutabled.setMonth(1) genuinely changes d in place, and every other variable referencing the SAME object sees that change too. Temporal objects are genuinely immutable — an operation like .add() genuinely returns a brand-new object, leaving the original completely untouched, verified directly.
  • 📌 Interview term: Temporal.PlainDate — represents a calendar date with genuinely no time-of-day and no timezone at all — verified directly, a PlainDate genuinely has no hour property — the correct type for something like a birthday, which is the same calendar date everywhere in the world.
  • 📌 Interview term: Temporal.ZonedDateTime — represents a real moment in time tied to a specific, real IANA timezone (like America/New_York), genuinely tracking the real UTC offset for that zone.
  • 📌 Interview term: Temporal.Instant — represents a single, absolute point in time, with no calendar or timezone attached at all — the closest Temporal type to a raw timestamp.
  • A precise answer names the real, direct fix for legacy Date's famous zero-indexed-month footgun: verified directly, new Date(2024, 0, 15)'s month is genuinely 0 for January, while Temporal.PlainDate's month property is genuinely 1 for January — a real, deliberate, verified correction.

Clarifying questions expected:

  • None — this is a definitional/comparison question; directly answering the prompt's own mutation question with real, verified proof is the strong signal.

Code / implementation expected: Yes — real, direct proof of Date's mutability versus Temporal's immutability, plus the month-indexing contrast, verified directly in a real browser (since Temporal is not yet in Node).

temporales2024date
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interviews. Difficulty: Hard

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every claim below was actually run in a real, current browser — Temporal is confirmed NOT y

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal, direct proof (verified in a real, current browser — Temporal is not yet in Node): Date genuinely mutates in place while Temporal is genuinely immutable, plus the real month-indexing fix
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 150 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track