Interview Q&A · JavaScript · 14 questions in this topic
Modern JavaScript (ES6+) — JavaScript Interview Q&A
What each era changed — from arrow functions to optional chaining, records and explicit resources. Part of Modern JavaScript (ES6+) · 204 questions in the JavaScript bank.
What did ES6/ES2015 change (the big bang)?
Answer
let/const, arrows, classes, modules, template literals, destructuring, spread/rest, default params, promises, Map/Set, symbols, iterators/generators, proxies. It modernized syntax, modularity and async foundations in one release — the baseline all later years extend.
Scope-plus-modules-plus-promises is the ES6 core.
Key points
- 1Syntax — arrows, classes, templates, destructuring.
- 2Scope — let/const, modules.
- 3Async/data — promises, Map/Set, symbols.
💡 Name one per bucket to show breadth, not a memorized list.
What did ES2016–ES2020 add (the usability years)?
Answer
Exponent operator and includes (2016); async/await, Object.entries/values, padStart/End (2017); rest/spread properties, Promise.finally (2018); flat/flatMap, Object.fromEntries, optional catch binding (2019); optional chaining (?.), nullish coalescing (??), BigInt, globalThis, Promise.allSettled (2020).
?.-plus-?? is the 2020 headline every codebase felt.
Example
const city = user?.address?.city ?? 'unknown'; // safe + defaulted
What did ES2021–ES2024 add?
Answer
Logical assignment (??=, &&=, ||=) and replaceAll, Promise.any (2021); at(), top-level await, class statics/fields, Error cause (2022); findLast, hashbang, Symbols-as-WeakMap-keys (2023); Object.groupBy, Promise.withResolvers, RegExp v-flag, Atomics.waitAsync (2024).
Recent years polish ergonomics (groupBy, at, withResolvers) over paradigm shifts.
Example
// config.port ??= 3000; // assign-if-nullish // arr.at(-1); // last element, readable
💡 groupBy-plus-at-plus-withResolvers is the 2024 trio to name.
How do optional chaining (`?.`) and nullish coalescing (`??`) work together?
Answer
?. short-circuits property access on null/undefined (no throw); ?? defaults nullish (not merely falsy) values. Combined: deep-safe reads with 0/''-preserving defaults — replacing lodash.get chains and ||-default bugs.
Safe-access-plus-nullish-default is the pairing mantra.
Key points
- 1?. — null-safe navigation (methods too: obj.fn?.()).
- 2?? — nullish-only defaults (keeps 0, false, "").
- 3??= — lazy assign-if-nullish.
Example
const port = cfg?.server?.port ?? 3000; // safe + 0-preserving
What are logical assignment operators (`??=`, `&&=`, `||=`)?
Answer
Compound assignment for logic: a ??= b assigns if nullish; a ||= b if falsy; a &&= b if truthy. They short-circuit (right side unevaluated when unneeded) — ideal for defaults, caches and conditional transforms.
Defaults (??=), fallbacks (||=), guards (&&=) is the use map.
Example
opts.timeout ??= 5000; // default if missing user.name ||= 'anon'; // fallback if falsy cfg.debug &&= sanitize(cfg.debug); // transform if truthy
💡 Short-circuit-plus-intent is why they beat if-statements.
What are `Map`/`Set` upgrades (and new Set methods in ES2025)?
Answer
Maps/Sets give arbitrary keys, size, order and O(1) ops over object-literal hacks. ES2025 adds mathematical Set methods (union, intersection, difference, symmetricDifference, isSubsetOf/SupersetOf/DisjointFrom) — set algebra natively.
Dictionaries-plus-algebra is the modern collection story.
Example
// new Set([1,2]).union(new Set([2,3])); // {1,2,3}What are private class features (fields, methods, statics) today?
Answer
#fields/#methods are hard-private per class (plus static variants), declared upfront, SyntaxError outside. Complements: private-in checks (#x in obj for brand guards) and static blocks for init.
Declare-upfront-plus-brand-checks is the encapsulation toolkit.
Example
class C { #s = new Set(); static isC(o) { return #s in o; } // brand check }
💡 in-checks (brand guards) are the deep-cut detail.
What is `Array.prototype.at()` and `findLast`/`findLastIndex`?
Answer
at(i) indexes with negatives (arr.at(-1) = last) — readable tail access. findLast(-Index) searches from the end (last matching error, final occurrence) without reversing. Both replace length-math and reverse-find hacks.
Negative-indexing plus reverse-search is the ergonomics win.
Example
arr.at(-1); // last element // arr.findLast((x) => x.failed); // last failure
What are Records & Tuples (the immutable-data proposal)?
Answer
Stage-2+ proposal: deeply-immutable, value-compared structures (#{a:1}, #[1,2]) — React-friendly state, Map keys by value, no defensive copies. Complement to const (binding) and freeze (shallow): structural immutability with equality.
Value-equality-plus-deep-freeze is the proposition.
Example
// #{ a: 1 } === #{ a: 1 }; // true (value equality, proposed)💡 Proposal-status honesty matters — stage, not shipped (as of 2024).
What is `structuredClone` and when did it obsolete JSON tricks?
Answer
Native deep clone (2022, all modern runtimes): Dates, Maps, Sets, typed arrays, cycles — not functions/DOM. JSON round-trip survives only for JSON-safe payloads crossing serialization boundaries (storage, network).
Clone-in-memory → structuredClone; serialize-across → JSON.
Example
const copy = structuredClone(state); // deep, typed, cyclic-safe
How do RegExp upgrades work (d, v flags, named groups, matchAll)?
Answer
Named groups (?<name>) plus matchAll iteration modernize extraction; d-flag adds indices; v-flag (2024) adds set notation and string-literal classes for Unicode correctness. dotAll (s) lets . span lines.
Named-plus-iterated is the modern extraction pattern.
Example
for (const m of text.matchAll(/(?<y>\d{4})-(?<m>\d{2})/g)) { // m.groups.y, m.groups.m }
💡 matchAll-plus-named-groups replaces exec-loops.
What is `Intl` (collators, dates, numbers, segments)?
Answer
The internationalization suite: Collator (linguistic sort), DateTimeFormat/NumberFormat (locale rendering, currencies), Segmenter (grapheme/word splits), ListFormat/PluralRules (grammar-aware joining). Correct i18n without dependencies.
Linguistic-truth-over-code-units is the Intl promise.
Example
new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }) .format(1234.5);
What modern habits mark code as genuinely current?
Answer
const-by-default, optional chaining/nullish, async/await over chains, modules, Map/Set over object-hacks, structuredClone over JSON tricks, AbortController cleanup, semantic-plus-accessible DOM, tested error paths.
Modern is intent-in-syntax, not version bingo.
Key points
- 1Syntax — const, ?., ??, modules.
- 2Async — await, allSettled, AbortController.
- 3Data — Map/Set, structuredClone.
💡 Close with intent-in-syntax — reads senior.
How do you stay current with JavaScript (yearly releases)?
Answer
Track TC39 proposals (stages 0-4), MDN compat tables, and runtime release notes; adopt stage-4-plus-baseline widely, polyfill deliberately, and gate syntax by build targets (browserslist). Yearly small releases reward continuous learning over big-bang upgrades.
Stage-4-means-shipped is the proposal rule of thumb.
Example
// .browserslistrc gates transpilation targetsRecommended resourcesAffiliate links · may earn us a commission