1let string = "1";
2let num = parseInt(string);
3//num will equal 1 as a int
1var myInt = parseInt("10.256"); //10
2var myFloat = parseFloat("10.256"); //10.256
1var arr = ['1','2','3'];
2arr = arr.map(x => parseInt(x));
3
4console.log(arr);
5//Array(3) [ 1, 2, 3 ]
1// Method - 1 ### parseInt() ###
2var text = "42px";
3var integer = parseInt(text, 10);
4// returns 42
5
6// Method - 2 ### parseFloat() ###
7var text = "3.14someRandomStuff";
8var pointNum = parseFloat(text);
9// returns 3.14
10
11// Method - 3 ### Number() ###
12Number("123"); // returns 123
13Number("12.3"); // returns 12.3
14Number("3.14someRandomStuff"); // returns NaN
15Number("42px"); // returns NaN
1const numberInString = "20";
2console.log(typeof(numberInString)) // typeof is string this is string in double quote " "
3const numInNum = parseInt(numberInString) // now numberInStrings variable converted in an Integer due to parseInt
4console.log(typeof(numInNum)) // this tell us the type of numInNum which is now a number
1let theInt = parseInt("5.90123"); //5
2let theFloat = parseFloat("5.90123"); //5.90123