Suggest an editImprove this articleRefine the answer for “[] == false ??”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`[] == false`** returns `true` because, when comparing with `==`, **JavaScript automatically coerces both sides to a number**, ultimately comparing `0 == 0`. **Key point:** `[]` first converts to `""`, then to `0`, while `false` converts straight to `0` - so `==` sees `0 == 0` and returns `true`; strict comparison `===` skips this and returns `false`.Shown above the full answer for quick recall.Answer (EN)Image## Short answer Because when comparing with `==`, **JavaScript automatically coerces both sides to a number**, and ultimately compares `0 == 0`. --- ## Step-by-step explanation Let's take: ```javascript [] == false ``` ### Step 1. `==` triggers **type coercion** With loose comparison (`==`), JS tries to coerce the types so the comparison is correct. The algorithm is described in the ECMAScript standard §7.2.14 as follows: > If one of the operands is `boolean`, it is coerced to a number. --- ### Step 2. Convert `false` → to a number ```javascript false → 0 ``` Now the expression looks like this: ```javascript [] == 0 ``` --- ### Step 3. JS sees that **the left side is an object (array)**, and the right side is a primitive If one of the operands is an object, it is first coerced to a **primitive** (via `valueOf()` → `toString()`). For the array `[]`: ```javascript [].toString(); // "" ``` So: ```javascript [] → "" // empty string ``` Now we have: ```javascript "" == 0 ``` --- ### Step 4. Comparing `"" == 0` According to the same algorithm: > If one operand is a string and the other is a number → the string is converted to a number. ```javascript Number("") → 0 ``` So: ```javascript 0 == 0 ``` Result: ```javascript true ``` --- ## Summary by steps | Step | Expression | What happened | |---|---|---| | 1 | `[] == false` | `false → 0` | | 2 | `[] == 0` | `[] → ""` | | 3 | `"" == 0` | `"" → 0` | | 4 | `0 == 0` | `true` | --- ## Why this is dangerous This logic makes `==` **unpredictable**. Here are more examples: ```javascript [] == ![] // true '' == 0 // true '0' == 0 // true null == undefined // true [] == '' // true [0] == 0 // true [1] == 1 // true [2] == 2 // true ``` --- ## How to avoid confusion Use **strict comparison** `===`, which **does not perform implicit type conversion**. ```javascript [] === false // false "" === 0 // false null === undefined // false ``` --- ## In short | Expression | What JS does | Result | |---|---|---| | `[] == false` | `[] → "" → 0`, `false → 0` | `true` | | `[] === false` | Compares without coercion | `false` |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.