The math object provides you properties and methods for mathematical constants and functions. Unlike other global objects,
Math
is not a constructor. All the properties and methods of Math are static
and can be called by using Math as an object without creating it.
Math Properties
Following is a list of all Math properties and its description.
| Sr.No |
Property & Description |
| 1 |
E
Euler's constant and the base of natural logarithms, approximately 2.718
|
| 2 |
LN2
Natural logarithm of 2, approximately 0.693
|
| 3 |
LN10
Natural logarithm of 10, approximately 2.302
|
| 4 |
LOG2E
Base 2 logarithm of E, approximately 1.442
|
| 5 |
LOG10E
Base 10 logarithm of E, approximately 0.434
|
| 6 |
PI
Ratio of the circumference of a circle to its diameter, approximately 3.14159
|
| 7 |
SQRT1_2
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707
|
| 8 |
SQRT2
Square root of 2, approximately 1.414
|
Exponential Functions
The basic exponential function is
Math.pow(), and there are convenience functions for square root, cube root, and powers of e, as shown in the following table.
Logarithmic Functions
The basic natural logarithm function is
Math.log (). In JavaScript, “log” means “natural logarithm.” ES6 introduced Math.log10 for convenience.
Miscellaneous Algebraic Functions
Following is a list of miscellaneous algebraic functions with their description.
Trigonometric Functions
All trigonometric functions in the Math library operate on radians, not degrees.
Math.random()
The
Math.random() function returns a pseudorandom number between 0 (inclusive) and 1 (exclusive).
Example: Pseudorandom Number Generation (PRNG)
var value1 = Math.random();
console.log("First Test Value : " + value1 );
var value2 = Math.random();
console.log("Second Test Value : " + value2 );
var value3 = Math.random();
console.log("Third Test Value : " + value3 );
var value4 = Math.random();
console.log("Fourth Test Value : " + value4 );
Output
First Test Value : 0.5782922627404332
Second Test Value : 0.5624510529451072
Third Test Value : 0.9336334094405174
Fourth Test Value : 0.4002739654388279
No comments:
Post a Comment