Optional Chaining (?.) — JS Technical Interview Questions & Answers

Safely reading deeply nested properties.

Optional Chaining (?.)

  • Optional Chaining (?.) (js) is a JS topic. In plain words you use it for a short Optional Chaining ?. js example in a script in the browser. Don’t start with a slogan — start with that picture.
  • Smallest example: the smallest Optional Chaining ?. js example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Optional Chaining (?.) (js).
  • From the example next to this theory: Safely reading deeply nested properties.
  • Trap: only saying “Optional Chaining ?. js” with no example. Fix that before you talk about advanced JS.
  • Viva: what is Optional Chaining (?.) (js)? Then show the smallest Optional Chaining ?. js example you can type. Then name the trap.

Technical Interview Tip: What is Optional Chaining (?.) (js)? Show this: the smallest Optional Chaining ?. js example you can type. Trap: only saying “Optional Chaining ?. js” with no example.

Code Examples for Optional Chaining (?.)

Optional Chaining (?.) — working example

const add = (a, b) => a + b;
const name = "Ada";
console.log(`Hi, ${name}!`);

const user = { name: "Lin", city: "Pune", skills: ["CSS"] };
const { city, ...rest } = user;
const skills = [...user.skills, "JS"];
console.log(add(2, 3), city, rest, skills);
console.log(user.profile?.bio ?? "n/a");

Optional Chaining (?.) — modern JS: arrows, template strings, destructuring, spread/rest, ?. and ?? for safe defaults.

How to Explain Optional Chaining (?.) to an Interviewer

What is Optional Chaining (?.) (js)?

Used for a short Optional Chaining ?. js example a script in the browser Not just the heading

Give one small example of Optional Chaining (?.) (js).

the smallest Optional Chaining ?. js example you can type Safely reading deeply nested properties

What mistake do beginners make with Optional Chaining (?.) (js)?

only saying “Optional Chaining ?. js” with no example Show the fix

Where do you use Optional Chaining (?.) (js)?

a script in the browser a short Optional Chaining ?. js example