Skip to content

Instantly share code, notes, and snippets.

@guipn
Last active December 12, 2015 06:19
Show Gist options
  • Save guipn/4728507 to your computer and use it in GitHub Desktop.
Save guipn/4728507 to your computer and use it in GitHub Desktop.
This won't throw a TypeError.
// re-written to eliminate need for premises regarding existence of `contacts[i]`.
if ( typeof contacts === 'object' &&
typeof contacts[i] === 'object' &&
typeof contacts[i].name === 'object' &&
typeof contacts[i].name.formatted !== 'undefined' &&
typeof contacts[i].phoneNumbers !== 'undefined' ) {
...
}
else {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment