Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why is [1, 2, 3] == "1,2,3" true?

Do you know what will be the output of this code?

JavaScript
console.log([1, 2, 3] == "1,2,3");
Show answer and explanation

The answer is true.

When an object is compared to a string with ==, it’s converted to a primitive. An array’s toString() joins its items with commas, giving "1,2,3".

Take the full quiz Next question →

More Type Coercion questions

  1. Why does [33, 2, 8].sort() not sort numbers correctly?
  2. What happens when you assign past the end of a JavaScript array?
  3. Why does [1, 2, 3].map(parseInt) return [1, NaN, NaN]?
  4. What does Array.push() return in JavaScript?
  5. How do you remove duplicates from an array with Set?

Related topics