bhylu.com

Advertisements

JS Date Set

Date setters mutate the existing object. Clone the date first when another part of the program needs the original.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const opening = new Date("2026-11-07T10:00:00Z");
const later = new Date(opening);
later.setUTCDate(later.getUTCDate() + 7);
console.log(later.toISOString());

What happens

The copy moves to 14 November while the original stays unchanged.