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

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -