Free programming examples and instructions

Convert to integer - Javascript

How to convert a value to integer in javascript

by Athil

Posted on 27 Jun 2018 Category: Javascript Views: 1086

Here I am going to show how to convert variable to integer in javascript.


var a = "10";
var b = parseInt(a); 

Here variable a is a string, and b is an integer.  The data type of a variable is defined by the value in it.

So tho do mathematical operations like +,-,*,%,% etc... need to convert integer before doing it.


var a = "10";
var b= "20";
c = parseint(a)* parseint(b);

Full Demo Code

<h1> Demo for conveting javascript to integer. </h1>
<input type="button" value="find sum" onclick = "findsum();"/> <br>

 function findsum()
	var a = "10";
	var b= "20";
	c = parseInt(a) * parseInt(b);



Leave a Comment:

Click here to register

Popular articles