JavaScript Math Objects

Mohammed Imtiyaz Mar 1, 2015

The JavaScript Math object allows you to perform mathematical tasks on numbers.

Math is not a constructor. All properties/methods of Math can be called by using Math as an object, without creating it.

The built-in Math object includes mathematical constants and functions. All the properties and methods of Math are static and can be called by using Math as an object without creating it.

Syntax

var pi_value = Math.PI;
var sine_value = Math.sin(30);

Math Objects

JavaScript Math Object Description Output
Math.random(); Creates random number using Math Object
Math.min(0, 120, 25, 16, -5); Find the lowest value in a list of arguments Returns -5
Math.max(0, 120, 25, 16, -5); Find the highest value in a list of arguments Returns 120
Math.round(3.7); - Returns 4
Math.round(3.5); - Returns 4
Math.round(3.3); - Returns 3
Math.ceil(3.4); Math.ceil() method returns a number up to the nearest integer Returns 4
Math.floor(3.7) Math.floor() method returns a number down to the nearest integer Returns 3

Math Constraints

JavaScript provides mathematical constraints that can be accessed with Math Objects. There are 8 mathematical constraints that can be accessed with Math Object.

Math Constraints Description
Math.PI Returns PI
Math.E Returns Euler's number
Math.SQRT2 Returns the square root of 2
Math.SQRT1_2 Returns the square root of 1/2
Math.LN2 Returns the natural logarithm of 2
Math.LN10 Returns the natural logarithm of 10
Math.LOG2E Returns base 2 logarithm of E
Math.LOG10E Returns base 10 logarithm of E