JavaScript Tutorial
JS - Introduction JS - Basic JS - Placement JS - Output JS - Statements JS - Syntax JS - Variables JS - Comments JS - Data Types JS - Operators JS - Operator Precedence JS - Condition JS - Switch JS - Functions JS - Objects JS - Loops For JS - Loops While JS - Break JS - Strings JS - String Methods JS - Numbers JS - Number Methods JS - Arrays JS - Array Methods JS - Array Iteration JS - Events JS - Event Listener JS - Event Propagation JS - Date JS - Math JS - Random JS - Boolean JS - Type Conversion JS - RegExp JS - Exception JS - Scope JS - Debugging JS - Hoisting JS - Strict Mode JS - this Keyword JS - Mistakes JS - Best Practices JS - Performance JS - Form Validation JS - ES6 Features
JS Objects
Object Definitions Object Properties Object Methods Object Constructors Object Prototypes
JS Functions
Function Definitions Function Parameters Function Call Function Apply Function Closures
JS HTML DOM
DOM Introduction DOM Methods DOM Selectors DOM HTML DOM CSS DOM Attributes DOM Navigation
JS Browser BOM
JS - Window JS - Screen JS - Location JS - History JS - Navigator JS - Popup Alert JS - Timing JS - Cookies
JS AJAX
AJAX - Introduction AJAX - XMLHttp AJAX - Request AJAX - Response AJAX - PHP
JS JSON
JSON - Introduction JSON - Syntax JSON - Data Types JSON - Parse JSON - Stringify JSON - Objects JSON - Arrays JSON - PHP JSON - JSONP
JS References
JavaScript Reference JavaScript Methods HTML DOM Reference

JavaScript Math Object

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

Unlike other global objects, the Math object has no constructor. Methods and properties are static.

All methods and properties can be used without creating a Math object first.


Math.PI

The Math.PI property represents the ratio of the circumference of a circle to its diameter, approximately 3.14159.

Run code

Note: All properties and methods of Math object are static and can be called by using Math as an object, without creating it.


Math.round()

The Math.round(x) method returns the value of x rounded to the nearest integer.

If the fractional portion of the argument is greater than 0.5, the argument is rounded to the integer with the next higher absolute value.

If it is less than 0.5, the argument is rounded to the integer with the lower absolute value.

If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +∞.

Run code

Math.pow()

The Math.pow(x, y) method returns the base to the exponent power, that is, baseexponent.

Run code

The first argument is the base number.

The second argument is the exponent used to raise the base.


Math.sqrt()

The Math.sqrt(x) method returns the square root of x.

Run code

Math.abs()

The Math.abs(x) method returns the absolute (positive) value of x.

Run code

Math.ceil()

The Math.ceil(x) method returns the value of x rounded up to the next highest integer.

Run code

Math.floor()

The Math.floor(x) method returns the value of x rounded down to the next lowest integer.

Run code

Math.sin()

The Math.sin() method returns the sine of the specified number.

This method returns a numeric value between -1 and 1, which represents the sine of the angle given in radians.

Run code

Math.cos()

The Math.cos() method returns the cosine of the specified number.

This method returns a numeric value between -1 and 1, which represents the cosine of the angle.

Run code

Math.max() and Math.min()

The Math.max() method returns the number with the highest value in a list of arguments.

Run code

The Math.min() method returns the number with the lowest value in a list of arguments.

Run code

Math.random()

The Math.random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).

Run code

You will learn more about Math.random() in the next chapter.


Complete Math Reference

For a complete properties and methods reference, visit our JavaScript Math Reference.

The reference section contains descriptions and examples of all Math properties and methods.