How to add or subtract one week from the current date in JavaScript?

Adding or subtracting one week from the current date is quite simple in JavaScript. We can get the current date as a number and then add or subtract 7 days with it.

Following is the code to add one week with current date:

Add one week with current date

  let numWeeks = 1;
  let currentDateObj = new Date();
  currentDateObj.setDate(currentDateObj.getDate() + numWeeks * 7);
  console.log(currentDateObj);

Subtract one week with current date

  let numWeeks = 1;
  let currentDateObj = new Date();
  currentDateObj.setDate(currentDateObj.getDate() - numWeeks * 7);
  console.log(currentDateObj);