Introduction

So many operations in mathematics are required for many functions in web platforms. Those operations are in the Math object of JavaScript objects.

Math Object in JavaScript

The Math object is used to perform simple and complex arithmetic operations.

The main properties and methods of Math Objects are given below.

Properties of Math Objects in JavaScript

These are some main properties of Math objects in JavaScript. There is a long list of methods for the Math objects; some are given below. Now let's learn about the methods in JavaScript.

Methods of Math Objects in JavaScript

That was a little bit about the Math Objects of JavaScript. Now let's do some exercises.

In the following exercise, we are trying to print the value of a given method.

Watch

<!DOCTYPE HTML>
<HEAD>
<TITLE>Math Functions</TITLE>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
document.write("Floor: "+Math.floor(12.6)+"<BR/>"); document.write("Log: "+Math.log(12.6)+"<BR/>");
document.write("Max: "+Math.max(12,34,15,65)+"<BR/>");
document.write("Min: "+Math.min(12,34,15,65)+"<BR/>"); document.write("Pow: "+Math.pow(10,2)+"<BR/>"); document.write("Random: "+Math.random()+"<BR/>"); document.write("Round: "+Math.round(12.6)+"<BR/>"); document.write("Sin: "+Math.sin(45)+"<BR/>");
document.write("Sqrt: "+Math.sqrt(16)+"<BR/>");
document.write("Tan: "+Math.tan(45)+"<BR/>");
</SCRIPT>
</BODY>
</HTML>

Various mathematical operations are performed in the preceding code using a math object.

So the output for the code above will be,

Floor: 12
Log: 2533606813957432
Max: 65
M12
Pow: 100
Random: 0.25858352379673395
Round: 13
S 0.8500035245341184 Sight:4
Tan: 16197751905435615