Javascript Math

Math.random()
This helps to return random number in between 0 and 1.

Code Structure
var math = Math.random();
alert(math);

Math.round()
This helps to return value of x rounded down to its nearest integar.

Code Structure
var round = Math.round(5.3);
alert(round);

Math.pow()
This helps to return value of x to the power of y.

Code Structure
var power = Math.pow(5,2);
alert(power);

Math.sqrt()
This helps to return square root of x.

Code Structure
var square = Math.sqrt(49);
alert(square);

Math.abs()
This helps to return positive value of x.

Code Structure
var absolute = Math.abs(-8.4);
alert(absolute);

Math.ceil()
This helps to return value of x rounded 'up' to its nearest integar.

Code Structure
var ceil = Math.ceil(8.4);
alert(ceil);

Math.floor()
This helps to return value of x rounded 'down' to its nearest integar.

Code Structure
var floor = Math.floor(8.4);
alert(floor);

Share this

Related Posts