Imagine a brand-new trainer who hasn't chosen a starter Codémon yet: trainer.starter is undefined. If you try to read trainer.starter.name, JavaScript crashes with an error because you cannot read .name on undefined!
Instead of writing long if checks everywhere, use optional chaining (?.). If the value before ?. is undefined or null, JavaScript stops right there and safely returns undefined instead of crashing:
↗️
Loading editor...
↶
↷
Here trainer.starter is undefined, so trainer.starter?.name calmly evaluates to undefined with zero errors.