JavaScript Math

Global Objects - Math :

Math :

Next object under the category of global objects in JavaScript is Math. It is the JavaScript object that is used to make mathematical calculations on the web.

We can call properties and methods of this object without instantiation of this object because the Math object cannot be instantiated.

JS Object Math Property
Method Name Description Code Snippet
max() It accepts multiple numeric values and returns the maximum out of them. Math.max(10,20,20.4,20.6,30.5) //Returns: 30.5
min() It accepts multiple numeric values and returns the minimum out of them. Math.min(10,20,20.4,20.6,30.5) //Returns: 10
ceil() It return upward rounded value of given number. Math.ceil(20.4) //Returns: 21
floor() It returns downward rounded value of given number. Math.floor(20.4) //Returns: 20
random() It returns any random number between 0 and 1 inclusive of 0 and exclusive of 1. Math.random() //Returns: 0.19083299074925186
round() It returns value of given number rounded to nearest integer. Math.round(30.5) //Returns: 31
sqrt() It returns square root of given number. Math.sqrt(9) //Returns: 3

Demo :

CODE/PROGRAM/EXAMPLE
document.write("Math.PI: " + Math.PI);
document.write("Math.SQRT2: " + Math.SQRT2 );
document.write(
  "Math.max(10,20,20.4,20.6,30.5): " +
	Math.max(10, 20, 20.4, 20.6, 30.5));
document.write(
  "Math.min(10,20,20.4,20.6,30.5): " +
	Math.min(10, 20, 20.4, 20.6, 30.5));
document.write("Math.ceil(20.4): " + Math.ceil(20.4));
document.write(
  "Math.floor(20.4): " + Math.floor(20.4));
document.write("Math.random(): " + Math.random());
document.write(
  "Math.round(30.5): " + Math.round(30.5) );
document.write("Math.sqrt(9): " + Math.sqrt(9));
#math_object_in_javascript #Math_object_javascript #math_and_date_object_in_javascript #javascript_arithmetic_operators

(New page will open, for Comment)

Not yet commented...