type coercion in JavaScript -
i guess kind of know differences between == , === in javascript, == type coercion when compare === not. understand following code true:
console.log(true == "1");
but when code below false?
console.log(true == "true");
when loosely compare boolean value of type, boolean coerced number.
and when compare number , string, string coerced number.
the full rules explained in the abstract equality comparison algorithm
the process this:
true == "true" ─┐ ├─ number(true) // 1 1 == "true" ─┤ ├─ number("true") // nan 1 == nan ─┤ ├─ // comparing `nan` produces `false` false ─┘
Comments
Post a Comment