Type Conversion:
A litle note about converting from one data type to another in JavaScript
:
What happens if you add a "string"
to a boolean
, Number
or another "string"
?
"string"
+boolean
:"string"
+Number
:Boolean
*Number
:"string"
*Number
:
JavaScript
assumes that the boolean
should be converted to a "string"
. Once done so,
the two are concatenated.
JavaScript
assumes that the Number
should be converted to a "string"
. Once done so,
the two are concatenated.
JavaScript
assumes that the boolean
should be converted to a Number
. Once done so,
the two are mathematically operated upon.
JavaScript
cannot be mathematically operated on by Numbers
, thus we have NaN.