Mathematical Functions

JavaScript has an inbuilt Math object that provides programmers with a range of useful numerical and mathematical functions. Examples of Math usage are rounding values and generating random values.

Function Description
Math.abs(x) Returns the Absolute value of x
Math.ceil(x) Returns the closest Integer to x and not less than x
Math.floor(x) Returns the closest Integer to x not greater than x
Math.max(x,y) Returns the maximum of x and y
Math.min(x,y) Returns the minimum of x and y
Math.random() Returns a pseudo random number between 0 and 1
Math.round(x) Returns the closest Integer to x

Note: Make sure that you always use a capital M when using the Math object.

Example Math Code 1