Objects are unordered string/symbol key maps. JSON is a data format: JSON.stringify and JSON.parse convert to and from strings for APIs and storage. Spread and destructuring copy enumerable own properties; they are shallow copies unless you clone deeper.
This JavaScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Literal:
{ title: "A", count: 1 }shorthand{ title }when the variable name matches. - Access:
obj.titleorobj["title"]for computed keys. - Keys:
Object.keys,values,entries. Iterateentriesinfor...of. - Spread:
const next = { ...prev, title }— shallow. Nested objects stay shared. - JSON:
JSON.stringify(obj)dropsundefined, functions, and symbols. - Parse: Wrap
JSON.parsein try/catch. Validate shape after parse. - Optional:
order?.customer?.emailavoidsCannot read property of undefined. - Clone:
structuredClone(obj)for most data. Spread is not deep.
Copy-paste examples
Safe JSON parse and a shallow update
Never JSON.parse untrusted strings without try/catch. Spread does not deep-copy nested objects.
function readSettings(raw) {
try {
const data = JSON.parse(raw);
if (data === null || typeof data !== 'object') return {};
return data;
} catch {
return {};
}
}
function setTitle(post, title) {
return { ...post, title, updatedAt: Date.now() };
}Common mistakes
- Using
JSON.parseonlocalStoragewithout try/catch after a user or another tab wrote junk. JSON.stringifyof objects with circular refs — it throws.- Mutating a nested object after a spread and wondering why React did not re-render.
- Treating JSON as “JavaScript” and pasting comments or trailing commas into
.jsonfiles.
FAQ
- Object vs Map?
Mapallows any key (including objects), remembers insertion, and has reliablesize. Use objects for records with known string keys.
- Why did stringify drop my field? The value was
undefinedor a function. Usenullif the API must see the key.
- Deep copy?
structuredClonefor most app data. Libraries for special cases. JSON round-trip loses dates (they become strings).
Related JavaScript cheat sheets
- Javascript Cheat Sheet 2026
- Javascript Array Methods Cheat Sheet
- Javascript String Methods Cheat Sheet
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.