0

How following code works?

var result = ["test"] == "test";
console.log(result); // returns true

I have tested in chrome and ["string"] == "string"` returns true.

4
  • 1
    see what ["test"].toString() results in ... then check out type coercion Commented Oct 25, 2017 at 10:13
  • 1
    In most of case, when doing == comparison in JS, JS implicitly converts arguments to string and then compares them, thus ["test"].toString() == "test" Commented Oct 25, 2017 at 10:15
  • @JaromandaX Thanks, It looked weird to me that this works :) Commented Oct 25, 2017 at 10:16
  • @HiteshBhayani use === to get what you expected (avoid type coercion). Commented Oct 25, 2017 at 10:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.