- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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...*/ );
- Related Articles
- How to set a cookie and get a cookie with JavaScript?
- How to read a cookie using JavaScript?
- Cookie Testing: Example Test Cases for Website
- How to check if a cookie is set in Laravel?
- Python – Test if tuple list has a single element
- How to set JavaScript Cookie with no expiration date?
- How to test if a parameter is provided to a function in JavaScript?
- How to test if a URL string is absolute or relative - JavaScript?
- How to set cookie value with AJAX request in JavaScript?
- How do you test if a value is equal to NaN in Javascript?
- How to test if a letter in a string is uppercase or lowercase using javascript?
- How to return an object by parsing http cookie header in JavaScript?
- How to test if an element contains class in JavaScript in HTML?
- How to check if a string has a certain piece of text in JavaScript?
- How do I create and read a value from the cookie in JavaScript?

Advertisements