Math Methods
Returns the absolute value of a number.
Math.abs(number) The number argument is a numeric expression for which the absolute value is sought.
Math.abs(number)
The number argument is a numeric expression for which the absolute value is sought.
The return value is the absolute value of the number argument. The following example illustrates the use of the abs method:
The return value is the absolute value of the number argument.
The following example illustrates the use of the abs method:
function ComparePosNegVal(n) { var s; var v1 = Math.abs(n); var v2 = Math.abs(-n); if (v1 == v2) s = "The absolute values of " + n + " and " s += -n + " are identical."; return(s); }
Returns the arccosine of a number.
Math.acos(number) The number argument is a numeric expression for which the arccosine is sought. number for acos must less or equal to 1.
Math.acos(number)
The number argument is a numeric expression for which the arccosine is sought. number for acos must less or equal to 1.
The return value is the arccosine of the number argument.
Returns the arcsine of a number.
Math.asin(number) The number argument is a numeric expression for which the arcsine is sought. number for acos must less or equal to 1.
Math.asin(number)
The number argument is a numeric expression for which the arcsine is sought. number for acos must less or equal to 1.
The return value is the arcsine of its numeric argument.
Returns the arctangent of a number.
Math.atan(number) The number argument is a numeric expression for which the arctangent is sought.
Math.atan(number)
The number argument is a numeric expression for which the arctangent is sought.
The return value is the arctangent of its numeric argument
Returns the angle (in radians) from the X axis to a point (y,x).
Math.atan2(y, x) The atan2 method syntax has these parts: Part Description Math Required. Invokes the intrinsic Math object. x Required. A numeric expression representing the cartesian x-coordinate. y Required. A numeric expression representing the cartesian y-coordinate.
Math.atan2(y, x)
The atan2 method syntax has these parts:
The return value is between -pi and pi, representing the angle of the supplied (y,x) point.
Returns the smallest integer greater than or equal to its numeric argument.
Math.ceil(number) The number argument is a numeric expression.
Math.ceil(number)
The number argument is a numeric expression.
The return value is an integer value equal to the smallest integer greater than or equal to its numeric argument.
Returns the cosine of a number.
Math.cos(number) The number argument is a numeric expression for which the cosine is sought.
Math.cos(number)
The number argument is a numeric expression for which the cosine is sought.
The return value is the cosine of its numeric argument.
Returns e (the base of natural logarithms) raised to a power.
Math.exp(number) The number argument is a numeric expression representing the power of e.
Math.exp(number)
The number argument is a numeric expression representing the power of e.
The return value is enumber. The constant e is Euler's constant, approximately equal to 2.178 and number is the supplied argument.
Returns the greatest integer less than or equal to its numeric argument.
Math.floor(number) The number argument is a numeric expression.
Math.floor(number)
The return value is an integer value equal to the greatest integer less than or equal to its numeric argument.
log Method Back to top
Returns the natural logarithm of a number.
Math.log(number) The number argument is a numeric expression for which the natural logarithm is sought. number must be larger than 0!
Math.log(number)
The number argument is a numeric expression for which the natural logarithm is sought. number must be larger than 0!
The return value is the natural logarithm of number. The base is e.
Returns the greater of two supplied numeric expressions.
retVal = Math.max(number1, number2) The max method syntax has these parts: Part Description retVal The greater of number1 or number2. number1 A numeric expression to be compared to number2. number2 A numeric value to be compared to number1.
retVal = Math.max(number1, number2)
The max method syntax has these parts:
Returns the lesser of two supplied numbers.
retVal = Math.min(number1, number2) The min method syntax has these parts: Part Description retVal The lesser of number1 or number2. number1 A numeric expression to be compared to number2. number2 A numeric value to be compared to number1.
retVal = Math.min(number1, number2)
The min method syntax has these parts:
pow Method Back to top
Returns the value of a base expression taken to a specified power.
Math.pow(base, exponent) The pow method syntax has these parts: Part Description base The base value of the expression. exponent The exponent value of the expression.
Math.pow(base, exponent)
The pow method syntax has these parts:
In the following example, a numeric expression equal to baseexponent returns 1000. Math.pow(10,3);
In the following example, a numeric expression equal to baseexponent returns 1000.
Math.pow(10,3);
random Method Back to top
Returns a pseudorandom number between 0 and 1.
Math.random( )
The pseudorandom number generated is between 0 and 1 inclusive. The random number generator is seeded automatically when JScript is first loaded. Click 2 or more times to see the result
round Method Back to top
Returns a supplied numeric expression rounded to the nearest integer.
Math.round(number) The number argument is the value to be rounded to the nearest integer.
Math.round(number)
The number argument is the value to be rounded to the nearest integer.
If the decimal portion of number is 0.5 or greater, the return value is equal to the smallest integer greater than number. Otherwise, round returns the largest integer less than or equal to number.
sin Method Back to top
Returns the sine of a number.
Math.sin(number) The number argument is a numeric expression for which the sine is sought.
Math.sin(number)
The number argument is a numeric expression for which the sine is sought.
The return value is the sine of its numeric argument
Returns the square root of a number.
Math.sqrt(number) The number argument is a numeric expression.
Math.sqrt(number)
If number is negative, the return value is zero
tan Method Back to top
Returns the tangent of a number.
Math.tan(number) The number argument is a numeric expression for which the tangent is sought.
Math.tan(number)
The number argument is a numeric expression for which the tangent is sought.
The return value is the tangent of number.
E Property
Returns Euler's constant, the base of natural logarithms. The E property is approximately equal to 2.718.
var numVar numVar = Math.E
LN2 Property
Returns the natural logarithm of 2.
var numVar numVar = Math.LN2
The LN2 property is approximately equal to 0.693.
LN10 Property
Returns the natural logarithm of 10.
var numVar numVar = Math.LN10
The LN10 property is approximately equal to 2.302.
LOG2E Property
Returns the base-2 logarithm of e, Euler's constant.
var varName varName = objName.LOG2E
The LOG2E property, a constant, is approximately equal to 1.442.
LOG10E Property
Returns the base-10 logarithm of e, Euler's constant.
var varName varName = objName.LOG10E
The LOG10E property, a constant, is approximately equal to 0.434
PI Property
Returns the ratio of the circumference of a circle to its diameter, approximately 3.141592653589793.
var numVar numVar = Math.PI
The PI property, a constant, is approximately equal to 3.14159
SQRT1_2 Property
Returns he square root of 0.5, or one divided by the square root of 2.
var numVar numVar = Math.SQRT1_2
The SQRT1_2 property, a constant, is approximately equal to 0.707.
SQRT2 Property
Returns the square root of 2.
var numVar numVar = Math.SQRT2
The SQRT2 property, a constant, is approximately equal to 1.414