Daily Software Tips & Tricks

Bite-sized knowledge to improve your coding skills daily.

Stop the Undefined Nightmares with Optional Chaining

April 24, 2026

Dealing with deeply nested objects in JavaScript used to mean writing long, ugly chains of if-statements or logical AND operators to avoid crashes. Now, we have optional chaining (using the ?. syntax). By adding a simple question mark before the dot, JavaScript will automatically return undefined if any part of the chain is missing instead of throwing a script-terminating error.

It keeps your code much cleaner and saves you from those annoying runtime crashes when an API response doesn't look exactly how you expected. It is a small syntax change that makes your codebase significantly more resilient.