Begin Web Programming with PHP & MySQL

Advertisements



JavaScript Math Object

The Math object is used to perform mathematical calculations on numbers. Math object is not a constructor. So all the properties and methods of Math are static and can be called by using 'Math' as an object.
Syntax:
var sine_value = Math.sin(45);

Properties of Math Object
Property Description
Math.E It returns Euler's number
Math.PI It returns PI value
Math.SQRT2 It returns the square root of 2
Math.SQRT1_2 It returns the square root of 1/2
Math.LN2 It returns the natural logarithm of 2
Math.LN10 It returns the natural logarithm of 10
Math.LOG2E It returns base 2 logarithm of E
Math.LOG10E It returns base 10 logarithm of E

Methods of Math Object
Method Description
abs() It returns the absolute value of a number.
acos() It returns the arccosine (in radians) of a number.
asin() It returns the arcsine (in radians) of a number.
atan() It returns the arctangent (in radians) of a number.
atan2() It returns the arctangent of the quotient of its arguments.
ceil() It returns the smallest integer, greater than or equal to a number.
cos() It returns the cosine of a number.
exp() It returns En, where N is the argument, and E is Euler's constant.
floor() It returns the largest integer, less than or equal to a number.
log() It returns the natural logarithm (base E) of a number.
max() It returns the larger of two given numbers.
min() It returns the smaller of two given numbers.
pow() It returns base to the exponent power, that is, baseexponent.
random() It returns the pseudo-random number between 0 and 1.
round() It returns the value of a number rounded to the nearest integer.
sin() It returns the sine of a number.
sqrt() It returns the square root of a number.
tan() It returns the tangent of a number.