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

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -