Optional Chaining
noun
say it: “OP-shuh-nul CHAY-ning” /ˈɒpʃənəl ˈtʃeɪnɪŋ/ or “KWES-chun mark DOT” /ˈkwɛstʃən mɑːrk dɒt/
The ?. operator in JavaScript: it reads a property only if the value before it exists, and gives undefined instead of an error when that value is null or undefined.
What is Optional Chaining in JavaScript?
Optional Chaining — The ?. operator, which stops and returns undefined when the value before it is nullish.
const customer = null;
const city = customer?.address?.city;
In a sentence
- “With optional chaining, runner.emergencyContact?.phone gave undefined instead of crashing for runners who left it blank.”
Level: Apprentice · More JavaScript terms at this level
Updated