Main Page

Math object

Property
Description
Error
Constructor for
Error
.
EvalError
Constructor for
EvalError
.
RangeError
Constructor for
RangeError
.
ReferenceError
Constructor for
ReferenceError
.
SyntaxError
Constructor for
SyntaxError
.
TypeError
Constructor for
TypeError
.
URIError
Constructor for
URIError
.
The Math object
The
Math
object is the built-in object that you wish you had during those high school math classes: It
knows all the formulas for the most complicated mathematical problems, and it can figure them out for
you if you give it the numbers to work with.
The
Math
object has several properties, consisting mostly of special values in the world of mathematics.
The following table describes these properties:
Property
Description
E
The value of e, the base of the natural logarithms.
LN10
The natural logarithm of 10.
LN2
The natural logarithm of 2.
LOG2E
The base 2 logarithm of
E
.
LOG10E
The base 1 logarithm of
E
.
PI
The value of
?
.
SQRT1_2
The square root of
1
?
2.
SQRT2
The square root of 2.
Although the meanings and uses of these values is outside the scope of this book, if you know what they
are, they are available when you need them.
The
Math
object also contains many methods aimed at performing both simple and complex mathemati-
cal calculations.
The methods
min()
and
max()
are used to determine which number is the lowest or highest in a group
of numbers. Each of these methods accepts any number of parameters:
var iMax = Math.max(3, 54, 32, 16);
alert(iMax); //outputs “54”
84
Chapter 3
06_579088 ch03.qxd 3/28/05 11:36 AM Page 84


JavaScript EditorFree JavaScript Editor     Ajax Editor


©

R7