// try using parsInt(x)
// you can then use typeof(x) to confirm
var myString = "555";
var myInt = parseInt(string);
console.log(typeof myInt); // number
// Converting a String into a Number in Javascript
// Longhand:
const num1 = parseInt("100");
const num2 = parseFloat("100.01");
console.log(num1);
console.log(num2);
// Shorthand:
const num3 = +"100"; // converts to int data type
const num4 = +"100.01"; // converts to float data type
console.log(num3);
console.log(num4);
var x = parseInt("1000", 10); // you want to use radix 10
// so you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])
// parseInt is one of those things that you say wtf javascript?
//if you pass to it any argument with number first and letters after, it
// will pass with the first numbers and say yeah this a number wtf?
let myConvertNumber = parseInt('12wtfwtfwtf');
console.log(myConvertNumber);
// the result is 12 and no error is throw or something
//but this
let myConvertNumber = parseInt('wtf12wtf');
console.log(myConvertNumber);
// is NaN wtf?
//if you truly want an strict way to know if something is really a real number
// use Number() instead
let myConvertNumber = Number('12wtf');
console.log(myConvertNumber);
// with this if the string has any text the result will be NaN
//shorthand method for casting a string into an int
let string = '1776';
let total = 10 - +string;
//above the addition symbol does the same as parseInt(string);
//result: total = 1766