Jak przekonwertować ciąg na int JS
let string = "1";
let num = parseInt(string);
//num will equal 1 as a int
Unusual Unicorn
let string = "1";
let num = parseInt(string);
//num will equal 1 as a int
var myInt = parseInt("10.256"); //10
var myFloat = parseFloat("10.256"); //10.256
const numberInString = "20";
console.log(typeof(numberInString)) // typeof is string this is string in double quote " "
const numInNum = parseInt(numberInString) // now numberInStrings variable converted in an Integer due to parseInt
console.log(typeof(numInNum)) // this tell us the type of numInNum which is now a number
// String to Int
myStringInt = "10";
console.log(parseInt(myStringInt)); // expected result: 10
// String to Float
myStringFloat = "8.33";
console.log(parseFloat(myStringFloat)); // expected result: 8.33
// String to any numeric type
console.log(Number(myStringInt)); // expected result: 10
console.log(Number(myStringFloat)); // expected result: 8.33
//For Integer
parseInt(string);
//For Float Or Double (Decimal Points)
parseFloat(string);
let int = "16";
int = +int;
console.log(int); // Output: 16
console.log(typeof int); Output: "number"