return "1"; // returns string
return +"1"; // returns int
I'd like to know what this method is called when using +"n" to convert from string to int.
It's just the intrinsic type coercion that the unary + operator performs according to the language spec.
So although conceptually it's just the opposite of unary -, since a + operation just means "multiply by positive 1" the only real work that's done is to coerce the value to a number.
From MDN:
Unary plus (+)
The unary plus operator precedes its operand and evaluates to its operand but attempts to converts it into a number, if it isn't already. Although unary negation (-) also can convert non-numbers, unary plus is the fastest and preferred way of converting something into a number, because it does not perform any other operations on the number. It can convert string representations of integers and floats, as well as the non-string values true, false, and null. Integers in both decimal and hexadecimal ("0x"-prefixed) formats are supported. Negative numbers are supported (though not for hex). If it cannot parse a particular value, it will evaluate to NaN.
Examples:
+3 // 3 +"3" // 3 +true // 1 +false // 0 +null // 0
+is being interpreted as "make this value positive"-type operation. a "negative string" doesn't exist, so the string-1 gets coerced to an int. it'd be no different if you hadreturn -"1", except you'd get a negative back instead