Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

Modern Syntax (ES6+) — JavaScript interview guide

11 / 23Language EssentialsHigh priorityEasy 25 min

Modern Syntax (ES6+)

Destructuring, spread/rest, template literals, optional chaining and nullish coalescing are used in almost every line of modern React code.

See it run

Press Play, or step with Next. Watch the highlighted line, the Call Stack and memory change together.

Destructuring, defaults, ?. , ?? and spread

Execution phaseStep 1/7
script.js
▶const user = { name: "Sumit", address: null };
2const { name, age = 24 } = user;
3const city = user.address?.city;
4const size = 0 ?? 10;
5const size2 = 0 || 10;
6const tags = ["js", "react"];
7const more = [...tags, "next"];
8console.log(name, age, city, size, size2, more);
Call Stack
last in, first out
Globalrunning
Memory / Scope
Global
user{ name: "Sumit", address: null }
Console

nothing printed yet

What happens:A user object. address is null on purpose.

Tip: click the box and use ← → keys to step, space to play.

Explained simply

The everyday features

Know what each does and when it returns undefined.

const { name, address: { city = "Delhi" } = {} } = user; // destructuring + defaults
const all = [...oldItems, newItem];        // spread
function log(first, ...rest) {}            // rest
const msg = `Hi ${name}`;                  // template literal
const zip = user?.address?.zip;            // optional chaining
const size = input ?? 10;                  // only null/undefined → 10
const size2 = input || 10;                 // 0, "", false → 10 too!

Remember this

  • ?? keeps 0 and empty string; || does not.
  • Spread makes a SHALLOW copy.
  • Arrow functions have no own this or arguments.

Interview questions

Difference between ?? and ||?

|| falls back for any falsy value (0, "", false, null, undefined, NaN). ?? falls back only for null or undefined.

Practice

  1. Swap two variables with destructuring.
  2. Merge two objects where the second wins.

Keep learning