The setDate() method sets the day of a date object (1-31):

Example

const d = new Date();
d.setDate(15);

The setDate() method can also be used to add days to a date:

Example

const d = new Date();
d.setDate(d.getDate() + 50);
If adding days shifts the month or year, the changes are handled automatically by the Date object.



Practice Excercise Practice now