--

Hi Chris, thanks so much for taking the time to read or respond! I thought the exact same thing — how did you end up with falsy or null values in an array anyway? When I was processing some strings using the RegExp .exec() function, which returns null, I finally found a use for this neat trick.

Personally, I find .filter() can be confusing to understand when it contains an if-else block. For me, it’s much easier to see the .filter(Boolean) // remove falsy line than to understand something spanning several lines.

Happy coding!

--

--

Dr. Derek Austin 🥳
Dr. Derek Austin 🥳

Written by Dr. Derek Austin 🥳

Hi, I'm Doctor Derek! I've been a professional web developer since 2005, and I love writing about programming with JavaScript, TypeScript, React, Next.js & Git.

Responses (1)