freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #28 of 61

dates · the Date object

LambdaVSThe Mutator
Lambda saysThe Date object represents a moment in time, built from now, a string, or parts.

new Date() is now; new Date("2026-05-28") parses ISO strings; new Date(year, monthIndex, day) builds from parts (month is 0-based!). Internally a Date is milliseconds since the Unix epoch (Date.now()). Date handling has sharp edges — many teams reach for a library for heavy work.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleCreate a specific date with parts (mind the 0-based month) and read its year.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const d=new Date(2026,4,28); // May (month 4)
document.getElementById('o').textContent=d.toDateString();</script></body></html>
▶ Open the interactive comic issue
‹ Generators · Function* · YieldDate Methods · Format · Parse · Arithmetic ›