The equality operator performs a series of type coercions in case the types mismatch, this is sometimes counterintuitive. As a rule of thumb, values of different types are usually converted to a number before comparing them again as numbers:
false == "0"
0 == "0"
0 == 0
true
As specified:
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
——-
The rules of == have little to do with truthiness - to observe whether a value would be truthy or falsy, use !!(<expression>) or Boolean(...) which forces a ToBoolean(...) conversion.
The equality operator performs a series of type coercions in case the types mismatch, this is sometimes counterintuitive. As a rule of thumb, values of different types are usually converted to a number before comparing them again as numbers:
false == "0"
0 == "0"
0 == 0
true
As specified:
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
The equality operator performs a series of type coercions in case the types mismatch, this is sometimes counterintuitive. As a rule of thumb, values of different types are usually converted to a number before comparing them again as numbers:
false == "0"
0 == "0"
0 == 0
true
As specified:
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
——-
The rules of == have little to do with truthiness - to observe whether a value would be truthy or falsy, use !!(<expression>) or Boolean(...) which forces a ToBoolean(...) conversion.
The equality operator performs a series of type coercions in case the types mismatch, this is sometimes counterintuitive. As a rule of thumb, values of different types are usually converted to a number before comparing them again as numbers:
false == "0"
0 == "0"
0 == 0
true
As specified:
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).