It's a hacky way, with a dynamically-typed language, to write terser code with potential null values. It doesn't really solve the problem of programmers forgetting to check for nullity, since there's nothing stopping a programmer from forgetting to use ? there.
Yep. This is why I always enable "strictNullChecks" (or "strict" in general) on every typescript project. You get an "object may be undefined" error and it doesn't compile.
4
u/wobsoriano Nov 10 '20
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
The optional chaining ‘?.’ is an error-proof way to access nested object properties, even if an intermediate property doesn’t exist.