Anh Thang Bui

29 Oct 2017 ~ 1 min read

Property lookup on booleans


Example:

Use below

if (typeof obj === 'object' && obj !== null) {
    return obj[key] || 0
}

return 0

Instead of

return (obj && obj[key]) || 0

Anh Thang Bui

Hi, I'm Thang.
I'm a software engineer from Hanoi, Vietnam. You can follow me on Twitter, see some of my work on GitHub, or read more about me on my website.