endJS

Arithmetic Inconsistency

What happens when you try to add a number and a string? Well JS converts the number into a string and concatenates them:

> '3' + 1
'31'

So how about subtraction?

> '3' - 1
2

In this case it converts the string into a number. This is a classic example of where you end up having to constantly test how the language works before using its basic features, because it is so unintuitive how addition and subtraction work.

It gets worse though, what about adding negative one instead of subtracting one, a distinction without a difference to anyone who has studied primary school level mathematics.

> '3' + - 1
'3-1'

Well that's embarrassing...