# getLocalStorageItem

## `this.getLocalStorageItem` Function

#### Description

With this method, a value previously stored in the browser’s **localStorage** can be retrieved. The function also checks whether the stored item has expired (based on its TTL) and automatically removes it if expired.

If the item is still valid, its expiration time is **renewed**, keeping it active for the same TTL duration again.

***

#### Parameters

| Name  | Type     | Description                                               |
| ----- | -------- | --------------------------------------------------------- |
| `key` | `String` | The key under which the item is stored in `localStorage`. |

***

#### Returns

| Type           | Description                                                                        |
| -------------- | ---------------------------------------------------------------------------------- |
| `Any` / `null` | Returns the value if the item exists and is not expired, otherwise returns `null`. |

***

#### Usage Example

```javascript
var value = this.getLocalStorageItem("my_test_key");
```

Retrieves the value previously stored under the key `"my_test_key"`.\
If the item exists and is still valid (not expired), the value is returned. Otherwise, `null` is returned.

***

#### Important Notes

* If the item is not found or has expired, the function returns `null`.
* If the TTL or expiry is missing (e.g., due to older format), the function will apply the current system default TTL.
* When a valid item is returned, its **expiration is updated**, extending its validity.
* The function checks if `localStorage` is available using `jentis.helper.bIsLocalStorageAvailable`.
* Do not use this function inside nested functions where the `this` context might be lost.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jentis.com/developer-guide/variables/client-side-variables/public-function-scope/getlocalstorageitem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
