como converter string para 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
// 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 = Number("1000")
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])
var num1 = 42;
var num2 = '42';
if (num1 == num2) {
console.log(true);
} else {
console.log(false);
}
// Will log `false`