JS Math Object Methods


abs(x) method: absolute value

var x = -3;
Math.abs(x); //|-3| = 3


acos(x) method: arccosine of x, in radians

var x = Math.acos(0.5); //x = 1.047197


asin(x) method: arcsine of x, in radians

var x = Math.asin(0.5); //x = 0.5235988


atan(x) method: arctangent of x, in radians

var x = Math.atan(5000); //x = 1.570596


atan2(y,x) method: arctangent of y/x

var x = Math.atan2(5000,1); //x = 1.570596
var x = Math.atan2(2500,0.5); //x = 1.570596


ceil(x) method: rounds up to the nearest integer

var x = Math.ceil(2.023); //x = 3


floor(x) method: rounds down to the nearest integer

var x = Math.floor(9.999); //x = 9


round(x) method: rounds to the nearest integer

var x = Math.round(9.999); //x = 10
var x = Math.round(2.023); //x = 2
var x = Math.round(9.51); //x = 10


cos(x) method: cosine

var x = Math.cos(Math.PI); //x = -1


sin(x) method: sine

var x = Math.sin(Math.PI/5); //x = 0.499999


tan(x) method: tangent

var x = Math.tan(Math.PI/4); //x = 0.999999999


exp(x) method: ex

var x = Math.exp(2); //x = e2 = 7.389056


log(x) method: ln(x), natural logarithm

var x = Math.log(Math.E); //x = ln(e) = 1


sqrt(x) method: square root

var x = Math.sqrt(4); //x = 2


random(x) method: generate a random number between 0 and 1

pow(x,y) method: xy

var x = Math.pow(3,4); //x = 81
var x = Math.pow(81,1/4); //x = 3


max(a,b,c,d,e ....) method: get the maximum value

var x = Math.max(3,4,32,12,500,-34); //x = 500


min(a,b,c,d,e ....) method: get the minimum value

var x = Math.min(3,4,32,12,500,-34); //x = -34


Math object built-in constants:

Contants
Description
Math.E:
Euler's number
Math.PI:
PI
Math.LN2:
ln2
Math.LN10:
ln10
Math.SQRT1_2:
square root of 1/2
Math.SQRT2:
square root of 2
Math.LOG10E:
lg(Math.E)
Math.LOG2E:
log210
convert.idontcarewhatyouthink.net © 2021  Terms of Use | Home