---
title: "Lifecycle of JavaScript Cookie"  
description: "Lifecycle of JavaScript Cookie"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156525/lifecycle-of-javascript-cookie  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Lifecycle of JavaScript Cookie

What is the Maximum [Lifetime](https://answers.mindstick.com/qa/34025/who-has-been-bestowed-with-the-v-shantaram-lifetime-achievement-award-2018) of [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) [cookie](https://www.mindstick.com/blog/123/what-is-cookie-poisoning)?

## Replies

### Reply by Anonymous User

The life span of JavaScript cookies depends on how long you set when creating cookies for example the following set a lifetime of 10 minutes. There is no way to get the cookie without expiration, i.e. you can set a life time cookie.

```
expiry = new Date();
expiry.setTime(date.getTime()+(10*60*1000));
```

// Ten minutes

// Date()'s toGMTSting() method will format the date correctly for a cookie

```
document.cookie = 'visited=yes; expires=' + expiry.toGMTString();
```


---

Original Source: https://www.mindstick.com/forum/156525/lifecycle-of-javascript-cookie

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
