"-0" does string-to-number conversion and therefore forces engine to perform addition:
("50" - 0) + 1 = 51
However, this trick (and the same like *1 etc) is considered "bad style".
"100" + 50
it doesn't know whether it should be adding two numbers or joining two strings, so by default, when it sees a number and a string, js automatically converts 50 to a string and then joins the two strings.
In js, all values from input fields and attributes are strings--even if they look like numbers. So, what you are doing in your code in this line:
"27" + 50
However, there is no subtraction operator for strings, so when js sees a subtraction operator:
"100" - 50
the only logical conclusion is that you are trying to subtract two numbers, so js converts the string to a number, and performs the subtraction. So, to convert a string to a number, you can subtract 0 from it.
("100" - 0) + 50
Similarly, you can convert a string to a number by multiplying by 1:
("100" * 1) + 50
However, it is not always clear what you are doing, so it's better style to use parseInt(), parseFloat() or Number() to convert the string to a number. parseInt() and parseFloat() will try convert a string to number if it has trailing letters:
but will return NaN if there are leading letters:
Number() returns NaN if there are any letters in the string. So, depending on what behaviour you want, you can use the appropriate function. In addition, it may prove useful to be able to test if the conversion to a number worked, and you have to use isNaN() for that:
var result = Number(value);
if(isNaN(result)) alert("not a number--bad input")