---
title: PREF
project: jComponent V19
version: 19.194
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v19/19-194/reference/pref/
updated: 2026-11-18T13:58:24.464Z
---

# PREF

> User preferences stored in the browser.

`PREF` stores small values with an expiration in the browser. The values are ready before the first components start. Stored paths can also be read with [GET()](../globals/#get), as explained in [Paths](../../guides/paths/).

## API

### PREF.get(key, [expire])

Type: `method`

Reads a stored value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | The key. |
| `expire` | `String` | no |  | Stores the value again with this expiration. |

Returns: `Object` The value, or `undefined` when it does not exist or has expired.

A stored value is also available as a property, for example `PREF.theme`.

Example: Read a value
```js
PREF.set('theme', 'dark');
console.log(PREF.get('theme')); // dark
console.log(PREF.theme); // dark
```

### PREF.set(key, [value], [expire])

Type: `method`

Stores a value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | The key. |
| `value` | `Object` | no |  | The value. |
| `expire` | `String` | no | `1 month` | For example `1 day`. |

Returns: `Object` The value.

Without a value, the key is removed. Watchers and components on the path `PREF.key` are notified. The data is saved after `DEF.delaypref` milliseconds. The keys `get`, `set`, `keys`, `load` and `save` are not available as properties.

Example: Store and watch a value
```js
WATCH('PREF.theme', function(path, value) {
	console.log(value); // dark
});
PREF.set('theme', 'dark', '1 day');
```

Example: Remove a value
```js
PREF.set('theme', 'dark');
PREF.set('theme');
console.log(PREF.theme === undefined); // true
```

### PREF.keys()

Type: `method`

Lists the stored keys.

Returns: `Array` The keys.

Example: List the keys
```js
PREF.set('theme', 'dark');
console.log(PREF.keys()); // ["theme"]
```

### PREF.load(callback)

Type: `method`

Reads the stored data when the page starts.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | yes |  | `function(data)`. |

Replace this function to read the data from another place. Pass the data to the callback as an object where each key holds `{ value, expire }`.

Example: Load from your own source
```js
PREF.load = function(callback) {
	callback({ theme: { value: 'dark', expire: NOW.add('1 day') } });
};
setTimeout(function() {
	console.log(PREF.theme); // dark
}, 500);
```

### PREF.save(data)

Type: `method`

Writes the stored data.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | yes |  | The data to save. |

Replace this function to save the data to another place. By default, the data goes to the browser storage under `DEF.localstorage` plus `.pref`.

Example: Save to your own target
```js
DEF.delaypref = 50;
PREF.save = function(data) {
	console.log(data.theme.value); // dark
};
PREF.set('theme', 'dark');
```
