I recently went through this typecast JS question:
Given '11'+10, the answer is 1110. It is clear that is not 21 because one is a string and JavaScript will treat both as string and perform concatenation instead of mathematical addition.
Why is '11'-10 is equal to 1, instead of something else?
Because the subtraction operator is not ambiguous and is only defined for numbers. Hence both operands are converted to numbers first.
See the specification:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With