JavaScript’s Weirdest Comparison

Published: (February 16, 2026 at 05:18 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Why [] == false is true

[] == false   // true

The == operator performs type coercion:

  1. false is converted to 0.
  2. [] is first converted to an empty string "".
  3. The empty string "" is then converted to 0.

Thus the comparison becomes:

0 == 0   // true

Why [] == ![] is true

[] == ![]   // true

Evaluation steps:

  1. ![] – an empty array is truthy, so applying ! yields false.
  2. The expression now is [] == false, which we already know evaluates to true (see above).

Takeaway

The == operator can produce surprising results because of implicit type conversion.
Most developers prefer the strict equality operator ===, which does not perform coercion and therefore avoids these pitfalls.

[] === false   // false
[] === ![]     // false

Understanding how coercion works removes the “weirdness” from JavaScript comparisons. Happy coding! ✨

0 views
Back to Blog

Related posts

Read more »

Base64 Decode - Base64 encoder/decoder

Overview Working with APIs, email attachments, or data URIs? Base64 Decode is a lightning‑fast tool for encoding and decoding Base64 data. All processing happe...

Preface

Motivation I wanted to record my studies to have consistency. Since I don't directly learn building projects from my CS program, I want to be an expert in my a...