(2 + 2) * (2 + 2);
('2' + '2') * ('2' + '2');
What do you think the answers are? It should be 16, right? Well, it should be, and the first equation does have an answer of 16. That second equation though is a little bit weird.
This ends up looking like this: (‘22’) * (‘22’).
If you would like to a take a closer look, you can check out my JSFiddle here.
Wait, wait, wait, you think. What happens if you multiply two strings that are actually letters. Like this: ‘what’ * ‘happens’ * ‘if’. (This is also in the JSFiddle, if you want to check that out.)
Well the type conversion still happens, but because you can’t actually multiply ‘what’ * ‘happens’ * ‘if’, the result it will give you is NaN, or Not a Number.
Kinda weird … but kinda cool, right?
Questions? Tweet me!