Last active
January 19, 2018 23:15
-
-
Save rileybracken/24c91dc74122e50afb79ba22fe32f249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const delivery = { | |
item: null, | |
}; | |
const andAndMethod = (delivery && delivery.item && delivery.item.name) || "Untitled Product"; | |
const typeOfMethod =( | |
typeof delivery != 'undefined' && | |
typeof delivery.item != 'undefined' && | |
typeof delivery.item.name != 'undefined' && | |
delivery.item.name | |
) || "Untitled Product"); | |
console.log(andAndMethod); // "Untitled Product" | |
console.log(typeOfMethod); | |
// "Error" (this is because item is null and it is checking for typeof undefined, | |
// more than likely it just wouldn't be there, but it IS possible it would be null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment