- ES6 - Discussion
- ES6 - Useful Resources
- ES6 - Quick Guide
- ES9 - New Features
- ES8 - New Features
- ES7 - New Features
- ES6 - Browsers
- ES6 - Image Map
- ES6 - Debugging
- ES6 - Multimedia
- ES6 - Animation
- ES6 - Validations
- ES6 - Proxy API
- ES6 - Reflect API
- ES6 - Object Extensions
- ES6 - Error Handling
- ES6 - Modules
- ES6 - Promises
- ES6 - Maps And Sets
- ES6 - Classes
- ES6 - Collections
- ES6 - Iterator
- ES6 - HTML DOM
- ES6 - RegExp
- ES6 - Math
- ES6 - Date
- ES6 - Arrays
- ES6 - New String Methods
- ES6 - Symbol
- ES6 - Strings
- ES6 - Boolean
- ES6 - Number
- ES6 - Objects
- ES6 - Page Printing
- ES6 - Void Keyword
- ES6 - Dialog Boxes
- ES6 - Page Redirect
- ES6 - Cookies
- ES6 - Events
- ES6 - Functions
- ES6 - Loops
- ES6 - Decision Making
- ES6 - Operators
- ES6 - Variables
- ES6 - Syntax
- ES6 - Environment
- ES6 - Overview
- ES6 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ES6 - Math
The math object provides you properties and methods for mathematical constants and functions. Unpke 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 pst of all Math properties and its description.
Sr.No | Property & Description |
---|---|
1 | Euler s constant and the base of natural logarithms, approximately 2.718 |
2 | Natural logarithm of 2, approximately 0.693 |
3 | Natural logarithm of 10, approximately 2.302 |
4 |
Base 2 logarithm of E, approximately 1.442 |
5 |
Base 10 logarithm of E, approximately 0.434 |
6 |
Ratio of the circumference of a circle to its diameter, approximately 3.14159 |
7 |
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707 |
8 |
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.
Sr.No | Function & Description |
---|---|
1 |
Returns x raised to the power y |
2 |
Returns the square root of the number x |
3 |
This method returns the cube root of a number x |
4 |
Equivalent to Math.pow(Math.E, x) |
5 |
Equivalent to Math.exp(x) – 1 |
6 |
Returns the square root of the sum of arguments |
Logarithmic Functions
The basic natural logarithm function is Math.log (). In JavaScript, “log” means “natural logarithm.” ES6 introduced Math.log10 for convenience.
Sr.No | Function & Description |
---|---|
1 |
Natural logarithm of x |
2 |
Base 10 logarithm of x |
3 |
Base 2 logarithm of x |
4 |
Natural logarithm of 1 + x |
Miscellaneous Algebraic Functions
Following is a pst of miscellaneous algebraic functions with their description.
Sr.No | Function & Description |
---|---|
1 |
Absolute value of x |
2 |
The sign of x: if x is negative,–1; if x is positive, 1; and if x is 0, 0 |
3 |
The ceipng of x: the smallest integer greater than or equal to x |
4 |
The floor of x: the largest integer less than or equal to x |
5 |
The integral part of x (all fractional digits are removed) |
6 |
x rounded to the nearest integer |
7 |
Returns the minimum argument |
8 |
Returns the minimum argument |
Trigonometric Functions
All trigonometric functions in the Math pbrary operate on radians, not degrees.
Sr.No | Function & Description |
---|---|
1 |
Sine of x radians |
2 |
Cosine of x radians |
3 |
Tangent of x radians |
4 |
Inverse sine (arcsin) of x (result in radians) |
5 |
Inverse cosine (arccos) of x (result in radians) |
6 |
Inverse tangent (arctan) of x (result in radians) |
7 |
Counterclockwise angle (in radians) from the x-axis to the point (x, y) |
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.4002739654388279Advertisements