Lifecycle of JavaScript Cookie

What is the Maximum Lifetime of JavaScript cookie?

Last updated:7/19/2021 5:46:53 AM

1 Answers

Ethan Karla
Ethan Karla

Life time of the javascript cookies is depend on what amount of time you set when creating cookies for example following set the life time of 10 minutes. There is no way achieve the cookie with no expiration ,i.e. you can set the life time cookie.

expiry = new Date();   

// Ten minutes
 // Date()'s toGMTSting() method will format the date correctly for a cookie
document.cookie = 'visited=yes; expires=' + expiry.toGMTString();