created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2013 04 18 true story bro

True story bro!

'true' == true // returns false

ProfessorWeb

The issue here is that strings are only implicitly converted to numbers when using the equality operator.

See The Abstract Equality Comparison Algorithm

  1. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
  2. If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
  3. If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
  4. If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y.

Failing to match any of these criteria, the algorithm returns false

@stevendesu

Fork me on GitHub