Web APIs

Storage.setItem()

Try the free JavaScript compiler

Stores a string value under a string key; may throw if storage cannot accept the write. Use an isolated test origin.

Formal Syntax & Structure

javascript syntaxjavascript
storage.setItem(key, value)

Parameters & Attributes

NameTypeDescription
keystringStorage key.
valuestringValue to store; converted to string.

Return Value

undefined

No return value.

Working Example

Example Snippetjavascript
const s=sessionStorage;try{s.setItem("bytemind-demo-theme","dark");console.log(s.getItem("bytemind-demo-theme"));}finally{s.removeItem("bytemind-demo-theme");}
JavaScript Reference