All Javascripts have access to a built-in object called document. The document object allows you to manipulate the current web page by accessing document properties and functions. For example,
document.write("Hello");
adds the text Hello to the browser window.
There are additional built-in objects that Javascript programmers can use. The Math object is another object to which all Javascript programmers have access.
Math has a property named PI and a property named E that have the approximate values of pi and e stored in them. Therefore, the statement
document.write(Math.PI, " is pi and e is ", Math.E);
would display
3.141592653589793 is pi and e is 2.718281828459045
Below is a summary of the functionality available through the use of the
Math object.
Function Purpose
Math.abs(num) returns the absolute value of num
Math.sin(angle) returns the sin, cos, or tan of angle,
Math.cos(angle) where angle is a radian measure
Math.tan(angle)
Math.acos(value) returns the angle (in radians) for the value
Math.asin(value) as calculated by the corresponding inverse trig function
Math.atan(value)
Math.exp(num) returns E to the num power and the natural
Math.log(num) log of num, respectively
Math.ceil(num) returns the smallest integer bigger than or equal to num
Math.floor(num) returns the largest integer less than or equal to num
Math.min(num1, num2) returns the smaller of num1 and num2
Math.max(num1, num2) returns the larger of num1 and num2
Math.pow(b, x) returns b to the x power
Math.round(num) returns the integer closest to num
Math.sqrt(num) returns the square root of num
|