How does making JavaScript Temporal date-and-time values unchangeable help code reuse them safely?
Show answer & explanation
Answer: An update creates a new value without altering a shared original
An update prevents every possible mistake without tests — Unchangeable values cannot prevent mistakes in program logic. Tests still need to check that the code calculates and uses the intended dates.
An update makes every calculation run faster automatically — Unchangeable values do not guarantee faster calculations. Their benefit is predictable behavior when different parts of a program share a value.
An update creates a new value without altering a shared original ✓ — Creating a new value leaves the original unchanged for other code that shares it. Adding a day to a Temporal date therefore does not unexpectedly change the date another function is using.
More Technology questions
- Why can a satellite redness index flag rusting Arctic rivers but still fail to tell which streams are chemically hazardous?
- A service publishes a fresh random number every minute, plus a public log in which each entry carries a fingerprint of the entry before it. What does that chaining add?
- Why can a wall of lava lamps used as a camera feed improve encryption even though the cryptographic software that consumes it is deterministic?
- If an attacker learns a pseudorandom generator's seed and algorithm after watching several outputs, why can the later outputs become reconstructable?
- Why does a physical noise source provide security against an attacker who knows the code, while a phone game shuffle does not?
- At parking-lot speed, why do quiet EVs need alert sounds before tire noise helps?