Concepts

Preference data minimization

Try the free JavaScript compiler

Persist only validated non-sensitive preferences; the example constructs the value without using Web Storage.

Formal Syntax & Structure

javascript syntaxjavascript
const saved = { theme, pageSize }

Working Example

Example Snippetjavascript
(async () => {const raw={theme:"dark",pageSize:20,privateNote:"synthetic"};const saved={theme:["light","dark"].includes(raw.theme)?raw.theme:"light",pageSize:[10,20,50].includes(raw.pageSize)?raw.pageSize:10};console.log(JSON.stringify(saved));})()
JavaScript Reference