Javascript Math numbers add operation can be performed by using plus (+) sign between two variables. Javascript Math object does not provide any method to perform add operation. Addition symbol (+) a plus sign is used to add two numbers but both variables should have number values otherwise it will concatenate both the values. If one variable is number or integer type and other variable has string type value enclosed in quotes then you can use Javascript parseInt function to convert the string value to number. Javascript parseInt function parses the first occurrence of number in the string passed to it but string should have number at its starting index. If string starts with white space then parseInt function trims the leading white space and returns the number. Thus you can add two different types of variable values by using parseInt to convert string to number and variable having number type value directly.

Examples of Javascript Math Number Add

var a =10;

var b ="10";

var c =" 20";

var d = 30; 

document.write(a + b);

document.write("<br>"); 

document.write(a + parseInt(c));

document.write("<br>"); 

document.write(a + d);

document.write("<br>"); 

document.write(parseInt(b) + parseInt(c));

// Output:
// 1010
// 30
// 40
// 30

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.