You may use the JavaScript Math object to execute mathematical operations. The following is a list of JavaScript Math methods, along with their descriptions.
Method | Description | Example | Output |
---|---|---|---|
abs() | Returns the absolute value | Math.abs(-9) | 9 |
acos() | Returns the arccosine value | Math.acos(-1) | 3.141592653589793 |
asin() | Returns the arcsine value | Math.asin(-1) | -1.5707963267948966 |
ceil() | Returns a smallest integer | Math.ceil(1.2) | 2 |
ceil() | Returns a largest integer | Math.floor(1.2) | 1 |
max() | Returns the highest value from a given number. | Math.max(5,-2,3,-7) | 5 |
min() | Returns the least value from a given number. | Math.max(5,-2,3,-7) | -7 |
sqrt() | Returns the square root of a given value. | Math.sqrt(64) | 8 |
round() | Number rounded to the nearest integer | Math.round( 10.3 ) | 10 |
Lets take an example of Math.random() method. This function returns a random number.
console.log(Math.random()); // 0.3938153920684837
console.log(Math.random()); // 0.41823122735824025
console.log(Math.random()); // 0.6175441817050966