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
Dateobject is genuinely mutable —d.setMonth(1)genuinely changesdin place, and every other variable referencing the SAME object sees that change too.Temporalobjects 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, aPlainDategenuinely has nohourproperty — 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 (likeAmerica/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 genuinely0for January, whileTemporal.PlainDate'smonthproperty is genuinely1for 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).