840Converting a string into a number in Javascript

var intStr = "101011";
var floatStr = "1.234";

The obvious solution is to parse the string into an integer, in most cases with base 10:
var int = parseInt(intStr, 10);    // 101011
var float = parseInt(floatStr);    // 1.234
A shortcut to coerce an integer string into a number is the addition of a ‘+’ sign before the integer string:
+intStr;    // 101011
+floatStr;    // 1.234
Care should be taken when removing the space between the equal and the plus sign. =+ converts to a number, += adds the stings together.
intStr = +intStr;    // 101011

intStr =+ intStr;    // 101011
intStr += intStr;    // "101011101011"  !!!!
We leave operations with the minus sign and multiple plus signs for another time.