Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Object JavaScript - avoid property access errors
// Here’s a verbose technique:
var motherName = undefined;
if(spot) {
if (spot.mother) motherName =;
// And here is a more concise way.
var motherName = spot && spot.mother &&;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment