CKTIS / JavaScript
Browser storage
Browser storage consists of browser-environment mechanisms for retaining client-side data. Learn the distinction between localStorage and sessionStorage and the boundary between the ECMAScript language and Web APIs.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
localStorage.setItem(key, value);
localStorage.getItem(key);
localStorage.removeItem(key);Browser storage (browser storage) is an environment facility, not ECMAScript syntax. The ECMAScript specification describes the language and its interaction with its host; it does not define localStorage or sessionStorage. Having Node 24 in a repository does not establish that these interfaces are available in a target browser.
localStorage retains key–value pairs across sessions, whereas sessionStorage is tied to a page session in a particular tab. Both interfaces are synchronous and store strings. getItem(key) returns null when the key is absent. Objects can be written using JSON.stringify and read using JSON.parse.
Access depends on the page's origin and browser policies. Data can be removed, and access or writes can throw; do not treat this storage as the only copy of data or as a place for secrets. The Web Storage section of the WHATWG HTML Standard defines localStorage and sessionStorage and their methods. It is not a browser compatibility reference and does not guarantee that these interfaces are available in the target browser.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Browser storage example</title>
</head>
<body>
<p>localStorage can persist across visits. sessionStorage is scoped to the page session in a tab. Both are browser APIs, not part of ECMAScript.</p>
<ul aria-label="Storage check results">
<li id="localStorage"></li>
<li id="sessionStorage"></li>
</ul>
<script>
const fixture = JSON.stringify({ theme: 'dark' });
function checkStorage(name) {
const result = document.getElementById(name);
try {
const store = window[name];
// A fresh temporary key avoids reusing application keys. This sequence is not atomic:
// another same-origin tab can change localStorage between calls.
const key = `cktis:storage:example:${crypto.getRandomValues(new Uint32Array(4)).join('-')}`;
if (store.getItem(key) !== null) {
throw new Error('Temporary storage key already exists');
}
store.setItem(key, fixture);
let saved;
try {
saved = store.getItem(key);
} finally {
store.removeItem(key);
}
if (saved !== fixture || store.getItem(key) !== null) {
throw new Error('Round trip or cleanup failed');
}
result.textContent = `${name}: read back theme=${JSON.parse(saved).theme}; temporary key removed.`;
} catch (error) {
if (!(error instanceof DOMException) || !['SecurityError', 'QuotaExceededError'].includes(error.name)) {
throw error;
}
result.textContent = `${name}: temporary write unavailable (${error.name}).`;
}
console.log(result.textContent);
}
checkStorage('localStorage');
checkStorage('sessionStorage');
</script>
</body>
</html>Result
A successful check reports that it read back theme=dark and removed the temporary key. If the check catches a DOMException named SecurityError or QuotaExceededError, it reports that the temporary write is unavailable and includes the error name. Other errors, including a temporary-key collision or a detected round-trip or cleanup failure, are rethrown without a report for that storage area. If the localStorage check rethrows, the sessionStorage check does not run.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.