The ES6 Math object contains so many properties and methods to perform some mathematical functions. The ES6 is an object that can be called without creating it. With the help of ES6 Math in JavaScript, you can store integers in the form of binary and octal notation. There are so many properties and functions available in ES6 Math. Also in the function section, there are lots of variety of functions mentioned below.
Math.random() function. This function returns the random number between 0 and 1.
Example:
javascript
var value1 = Math.random(); console.log( "The random function value : " + value1 ); |
Output:
The random function value : 0.603934617864549
ES6 Math() Functions type: Following list shows the functions types of ES6 Math object:
- Exponential Functions
- Logarithmic Functions
- Miscellaneous Algebraic Functions
- Trigonometric Functions
ES6 Math Exponential Functions: There are so many functions for like square root, cube root, and powers of e, as shown in the below table. The Math.pow() is the basic function of the Exponential Functions. Some other functions are listed below along with their brief descriptions:
Function | Description |
---|---|
Math.pow() Function | This function returns the base to the exponent power. |
Math.sqrt() Function | This function returns the square root of a number. |
Math.cbrt() Function | This function returns the cube root of a number. |
Math.exp() Function | This function is equivalent to Math Pow() Function. |
Math.expm1(X) Function | This function is equivalent to Math exp()-1. |
Math.hypot(x1, x2, …) Function | This function returns the square root of the sum of the arguments. |
ES6 Math Logarithmic Functions: In the Logarithmic section there are 4 functions but the basic one is Math.log() function, this is natural logarithmic. The ES6 introduce the Math.log10() function in JavaScript before ES6 there is no log10 in the entire JavaScript. Other functions are listed below:
Function | Description |
---|---|
Math.log(x) Function | This function returns the natural logarithm of X. |
Math.log10(x) Function | This function returns the base 10 logarithm of X. |
Math.log2(x) Function | This function returns the base 2 logarithm of X. |
Math.log1p(x) Function | This function returns the natural logarithm of 1+x. |
ES6 Math Miscellaneous Algebraic Functions: There are lots of functions in this section mentioned below with the brief description. Following are some of the listed functions:
Function | Description |
---|---|
Math.abs() Function | This functions returns the exact value of the number. |
Math.sign() Function | This functions returns the sign of the exact number. |
Math.ceil() Function | This function returns the smallest integers greater than or equal to the exact number mens the ceiling value. |
Math.floor() Function | This function returns the floor value of the exact number. |
Math.trunc() Function | This function returns the trim value of exact number means remove the decimal right digit. |
Math.round() Function | This function returns the rounds of the exact number. |
Math.min() Function | This function returns the smallest of zero or more numbers if no arguments are given the it will return the +infinity. |
Math.max() Function | This function returns the largest of zero or more numbers if no arguments are given the it will return the -infinity. |
ES6 Math Trigonometric Functions: There are lots of functions in Trigonometric Functions but all the functions deals with the radians but the degree is not valid in this section. Following are some of the listed trigonometric functions:
Function | Description |
---|---|
Math.sin() Function | This function returns the sin of the exact number. |
Math.cos() Function | This function returns the cosine of the exact number. |
Math.tan() Function | This function returns the tangent of the exact number. |
Math.asin() Function | This function returns the inverse sin of the exact number. |
Math.acos() Function | This function returns the inverse cosine of the exact number. |
Math.atan() Function | This function returns the inverse tangent of the exact number. |
Math.atan2() Function | This function returns a numeric value between -pi and pi representing the angle theta of the exact two points. |
ES6 Math properties list with there brief description: Following is the list of ES6 Math properties along with their brief descriptions in it:
Property | Description |
---|---|
Math-E Property | This property define the Euler’s constant(2.718) |
Math-LN2 Property | This property defines the natural log2(0.693) |
Math-LN10 Property | This property defines the natural log10(2.302) |
Math-LOG2E Property | This property defines the base 2 logarithm of E(1.442) |
Math-LOG10E Property | This property defines the base 10 logarithm of E(0.434) |
Math-PI Property | This property defines the ratio of the circumference of a circle to its diameter(3.14159) |
Math-SQRT1_2 Property | This property defines the square root of 1/2(0.707) |
Math-SQRT2 Property | This property defines the square root of 2(1.414) |
Note: The Edge and the Safari is the first two browser that support all the ES6 features.
Supported Browsers: The browsers supported by ES6 Math are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera