Example 1 — Read the Weekday Index
Call getDay() on a fixed local date (month index is zero-based).
const birthday = new Date(1975, 7, 19); // Aug 19, 1975
console.log(birthday.getDay()); // 2 (Tuesday) How It Works
- Build a local date.
new Date(1975, 7, 19)is August 19, 1975 (month index7). - Read the weekday.
getDay()returns2— Tuesday in the 0–6 scale. - Scale reminder.
0= Sunday, so Tuesday lands at2. - No side effects. The
Dateis unchanged;getDayonly reads.

