Test if a JavaScript Cookie has Expired



To test if a cookie has expired in JavaScript, add the following condition and check −

if( !($.cookie('myCookie') === null) ) {
   // Do something (cookie exists)
} else {
   // Do something (cookie expired)
}

You can also check it using a single line code −

checkCookie = $.cookie('myCookie') === null ?
( /*Condition TRUE...*/ ) : ( /*Condition FALSE...*/ );
Updated on: 2020-06-17T06:43:19+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements