What is the output?
let n = 0; const p = null; p?.f(n++); console.log(n);
- 0
- 1
- undefined
- TypeError
Optional chaining short-circuits the whole call when p is null, so the argument n++ is never evaluated.
Play Problem Solving ▸
let n = 0; const p = null; p?.f(n++); console.log(n);