Question 18
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log([1, 2] == "1,2", [1, 2] === [1, 2], [] + 1, [5] * 2);
- A false false 1 10
- B true false 1 10 Correct
- C true true 1 NaN
- D false false NaN NaN
Correct Answer: Option B
Arrays convert to strings when a primitive is involved: [1, 2] → "1,2", [] → "" ("" + 1 = "1"), [5] → "5" → 5 for *. Two arrays are compared by reference.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!