<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh" -->

---
title: filter(Boolean) is convenient, but it’s not a nullish...
description: Using filter(Boolean) to clean arrays in JavaScript/TypeScript removes falsy values like 0, false, and empty strings, not just null and undefined, which can...
canonical: https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: filter(Boolean) is convenient, but it’s not a nullish filter. | daily.dev
og:description: Using filter(Boolean) to clean arrays in JavaScript/TypeScript removes falsy values like 0, false, and empty strings, not just null and undefined, which can...
og:url: https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh
og:image: https://api.daily.dev/og/posts/xnBAV9NnH.png
og:image:alt: filter(Boolean) is convenient, but it’s not a nullish filter.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# filter(Boolean) is convenient, but it’s not a nullish filter.

**[Javascript ](https://daily.dev/sources/code_with_js)** · [@nyaomaru](https://daily.dev/nyaomaru) · 1 min read · 3 upvotes · 0 comments

## Summary

Using filter(Boolean) to clean arrays in JavaScript/TypeScript removes falsy values like 0, false, and empty strings, not just null and undefined, which can silently discard valid data. Additionally, TypeScript's type checker doesn't recognize Boolean as a type guard, so it won't narrow the array type to exclude null and undefined even though they're removed at runtime. A proper nullish-only filter or a dedicated type guard function is needed instead.

## Content

Valid values like 0, false, and "" can disappear too.

Falsy ≠ Nullish.

```ts
const result = values.filter(Boolean);

// Array<string | number | boolean | null | undefined>
```

There’s a TypeScript side to `filter(Boolean)` too. 👀

It removes falsy values at runtime, but `Boolean` isn’t a type guard.

So TypeScript doesn’t generally know that `null` and `undefined` are gone.

More in my latest article 👇

https://dev.to/nyaomaru/why-filterboolean-is-not-a-nullish-filter-in-typescript-4m82

#TypeScript #JavaScript #OpenSource

## Similar posts on daily.dev

- [Stop turning everything into arrays \(and do less work instead\)](https://daily.dev/posts/stop-turning-everything-into-arrays-and-do-less-work-instead--dxynqatj1) · Matt Smith · 18 upvotes · 0 comments
- [Stop Using TypeScript's Exclamation Mark](https://daily.dev/posts/stop-using-typescript-s-exclamation-mark-re1atfub4) · TypeScript.TV · 258 upvotes · 16 comments
- [Greater Than False](https://daily.dev/posts/greater-than-false-l8c9ruzeo) · The Daily WTF · 1 upvotes · 0 comments
- [Handling Null and Undefined with ‘??’](https://daily.dev/posts/handling-null-and-undefined-with--vopbeffru) · JavaScript in Plain English · 26 upvotes · 1 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh","headline":"filter(Boolean) is convenient, but it’s not a nullish filter.","text":"Using filter(Boolean) to clean arrays in JavaScript/TypeScript removes falsy values like 0, false, and empty strings, not just null and undefined, which can silently discard valid data. Additionally, TypeScript's type checker doesn't recognize Boolean as a type guard, so it won't narrow the array type to exclude null and undefined even though they're removed at runtime. A proper nullish-only filter or a dedicated type guard function is needed instead.","url":"https://daily.dev/posts/filter-boolean-is-convenient-but-it-s-not-a-nullish-filter--xnbav9nnh","datePublished":"2026-09-17T15:28:43.714Z","dateModified":"2026-09-17T15:29:02.368Z","author":{"@type":"Person","name":"nyaomaru","url":"https://daily.dev/nyaomaru","image":"https://avatars.githubusercontent.com/u/90489696?v=4","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":560}},"image":"https://media.daily.dev/image/upload/s--SjC3-qnv--/f_auto/v1789658925/posts/xnBAV9NnH?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/code_with_js","name":"Javascript "}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Javascript ","item":"https://daily.dev/squads/code_with_js"},{"@type":"ListItem","position":3,"name":"filter(Boolean) is convenient, but it’s not a nullish filter."}]}
```

