How to convert a string to number
You can convert a string to number using unary operator '+' or parseInt(number,10) or Number()
check these snippets
var num1a = "1";
console.log(+num1a);
var num1b = "2";
num1b=+num1b;
console.log(num1b);
var num3 = "3"
console.log(parseInt(num3,10));
var num4 = "4";
console.log(Number(num4));
Hope it helps
No questions are dumb.
a quick answer:
to convert a string to a number you can use the unary plus.
var num = "82144251";
num = +num;
Doing num = +num
is practically the same as doing num = num * 1;
it converts the value in a to a number if needed, but after that it doesn't change the value.
It looks like you're looking for the Number()
functionality here:
var num = "82144251"; // "82144251"
var numAsNumber = Number(num); // prints 82144251
typeof num // string
typeof numAsNumber // number
You can read more about Number()
here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
Hope this helps!