by schneidmaster · 7y ago · 0 comments
That's not the case AFAIK - checking in both node and FireFox, `true && null` evalutes to `null`, `true && undefined` evaluates to `undefined`, and `true && null && true` again evaluates to `null`. In what scenario does `&&` coerce the returned value to a boolean?
EDIT: checked MDN's docs at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... - it seems to indicate that there is no such coercion of falsy values to false.
Your example would become:
// this won't throw an exception if foo is null
_.get(foo, 'bar.baz')
And you can even set a default value to return if it is:
https://lodash.com/docs/4.17.11#get