JavaScript filter(Boolean) removes falsy values

One line of JavaScript that can bite… or save you Ever seen this before? const arr = ["", null, undefined, false, 0, 1, 2]; const cleaned = arr.filter(Boolean); ✅ Output: [1, 2] filter(Boolean) removes all falsy values in JavaScript. ⚠️ That includes: - false - 0 - "" - null - undefined It’s a beautifully clean ES6 trick — but only if you actually want to remove everything falsy. #JavaScript #WebDevelopment #FullStack #Frontend #CleanCode #ES6 #ProgrammingTips

To view or add a comment, sign in

Explore content categories