How to Convert string into integer in JavaScript?

admin
By -
0

 
For Converting JavaScript string variable we are going to use JavaScript type conversion for number


First We have to create an string variable 
and now we create next  with using Number Function
and Third variable for checking type of converted variable


<html>
<head>
<style>
</style>
</head>
<body>
<h1>Javascript Convert String Into Integer or Number</h1>

<p id="demo"></p>
<p id="type"></p>
<script>
var mysrtring = "25245"; //this string becaue of double -auotes around the numbers

let mynum = Number(mysrtring); // here we are using typeconversion to conver string var into number
var mytype = typeof(mynum); //get which type of our var is?

document.getElementById("demo").innerHTML = mysrtring;

document.getElementById("type").innerHTML = mytype;
console.log(typeof(mynum));

</script>

</body></html>




Result is Here:


 Thank You

Follow for More 


Post a Comment

0Comments

Put Your Thought or Query Here

Post a Comment (0)