JavaScript 2025 cheatsheet
JavaScript 2025: Objects and data
9 common JavaScript 2025 tasks.
Destructure an object
Pull properties into variables, with a default for a missing one.
const { name, email = "none" } = user;
Merge objects
Combine objects. Later properties win.
const settings = { ...defaults, ...overrides };
Loop over an object
Iterate over keys and values.
for (const [key, value] of Object.entries(obj)) {
console.log(key, value);
}
Build an object from pairs
Turn an array of [key, value] pairs into an object.
const obj = Object.fromEntries([["a", 1], ["b", 2]]);
Read nested properties safely
Return undefined instead of throwing when something in the chain is null or undefined.
const city = user?.address?.city;
Use a default only for null or undefined
Unlike ||, it keeps 0 and empty strings.
const port = config.port ?? 3000;
Deep copy an object
Copy nested data, including dates and maps.
const copy = structuredClone(original);
Convert to and from JSON
Pretty-print an object as JSON, and parse JSON text back.
const text = JSON.stringify(data, null, 2);
const parsed = JSON.parse(text);