Language syntax

Optional chaining (?.)

Try the free JavaScript compiler

Short-circuits a continuous optional chain on null or undefined and returns undefined. Computed keys or arguments are skipped when short-circuited. A present noncallable still throws on optional call; an undeclared base still raises ReferenceError.

Formal Syntax & Structure

javascript syntaxjavascript
base?.property; base?.[key]; fn?.();

Return Value

any

Access or call result, or undefined after nullish short-circuit.

Working Example

Example Snippetjavascript
let i=0; const a=null; console.log(a?.[i++],i);
JavaScript Reference