Clearing localStorage with setTimeout ()?

  • 0
    The cart is stored in localStorage. According to tz, the data must be kept for a month.
    Not critical if cleaned via setTimeout ()?
    JavaScript Anonymous, May 19, 2020

  • 2 Answers
  • 0
    It is not entirely clear how setTimeout will approach this problem. You don't expect the user to leave the tab this month, do you?

    In my opinion, it is more expedient to store the creation date of the cart in localStorage. Then, using a script, check whether 30 days have passed since the basket was created. If so, empty the trash.

  • 0
    by tz, the data must be kept for a month.

    Users can clear ls themselves whenever they want.

    Not critical if cleaned with setTimeout ()?

    This is critical, as setTimeout () will work while the user is on the page and your timer may not fire at the right time.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!