Example:
Use below
if (typeof obj === 'object' && obj !== null) {
return obj[key] || 0
}
return 0
Instead of
return (obj && obj[key]) || 0
29 Oct 2017 ~ 1 min read
Use below
if (typeof obj === 'object' && obj !== null) {
return obj[key] || 0
}
return 0
Instead of
return (obj && obj[key]) || 0
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.