Math class Random() method Floor method Top-level parseInt function JavaScript Math class Random() method Floor method Top-level parseInt function
Math Class Constants and Math Functions Constant Description Actual value Math.E The base of the natural log system 2.718281828459045 Math.LN10 Natural logarithm of 10 2.302585092994046 Math.PI Ratio of circle circumference to diameter 3.141592653589793 Math.SQRT2 Square root of 2 1.4142135623730951 Math.sqrt(x) Square root of x Math.pow(x, n) Returns x to the power of n Math.log(n) Returns the natural logarithm of n Math.exp(n) Returns e to the power of n
Rounding Functions and Random Numbers Description 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Math.round(x) Rounds to the nearest integer Math.floor(x) Rounds down to the nearest integer Math.ceil(x) Rounds up to the nearest integer Math.random() Random value between 0 and <1 Math.min(a, b, c) Returns the lowest value from list Math.max(a, b, c) Returns the highest value from list
ParseInt function syntax: parseInt( 'string' [, base] ) Semantics: The first argument of parseInt must be a string. The second argument, optional, specifies the number base of the string. The base argument can be any integer from 2 to 36. The function converts a string into an integer. If there is only one argument, the number base is detected according to the general JavaScript syntax for numbers. Strings that begin with 0x or -0x are parsed as hexadecimals; strings that begin with 0 or -0 are parsed as octal numbers. All other strings are parsed as decimal numbers.