Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Cookie not expiring in JS after setting date to 1970

I am trying to delete some cookies BEFORE MY REQUEST IS SENT to my backend so I set expiration date for those cookies to be Thu, 01 Jan 1970 00:00:00 UTC, expecting for my backend service to not see any of those cookies when handling the request.

The process to delete cookies, as far as I know, is to set the expiration date of the cookies to be a past date (As I am doing) but for some reason cookies seem to be still alive.

This is what I currently have:

let badCookies = ['cookieName1', 'cookieName2', 'cookieName3'];
      badCookies.forEach((cookieName) => {
          document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
        });

if(GetCookie('cookieName1') === null) {
    // Must fall here since cookieName1 has been forced to expire
} else {
    // ERROR: cookie still alive, I am actually falling here that's the main issue
}

I don't really know what can be wrong, a simple process keeps causing problems and I cannot find any solution for this. I have searched in several websites but the answer for delete the cookies are always the same, setting the expiration date to force cookie to be deleted before making a request.

The process is described here:

Delete cookie by name?

and also here:

https://www.w3schools.com/js/js_cookies.asp

I have tried both strings without success.

I am using this to check for cookie to see if it is still valid:

Check if cookie is still valid

Sorry if this question seems like duplicate but none of the answers in similar stack overflow posts could help me that's why I decided to post my own question.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!