3 ms·
There is no expected output. It doesn't make sense to subtract the value 1 from the string "wat". But Javascript will cast both of them to numbers, then try to
by squeaky-clean 12y ago
There is no expected output. It doesn't make sense to subtract the value 1 from the string "wat". But Javascript will cast both of them to numbers, then try to subtract 1 from NaN. However, if you do "wat" + 1, Javascript will cast both of them to strings, and append "1" to "wat".
It's not just the odd behavior, but the inconsistency.
- hfsktr 12y agoOk that makes a bit more sense. I didn't even think about how it would be if you tried to add them. I like javascript but I don't do anything so complicated (or maybe not the right types of things) that I run into many of these situations.