1let string = "1";
2let num = parseInt(string);
3//num will equal 1 as a int
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
1let theInt = parseInt("5.90123"); //5
2let theFloat = parseFloat("5.90123"); //5.90123
1//It accepts two arguments.
2//The first argument is the string to convert.
3//The second argument is called the radix. This is the base number used in mathematical systems. For our use, it should always be 10.
4
5
6var text = '42px';
7var integer = parseInt(text, 10);
8
9
10// returns 42