Mathematics is an integral part of computing and coding. Programmers use mathematical methods and expressions to perform calculations for all kinds of different reasons during development. Fortunately, JavaScript provides various built-in methods that can make your life easier.

In this article, you’ll learn 19 JavaScript math methods you should master today.

## 1. Math.abs ()

the abs () The method returns the absolute value of a number.

``let num1 = 32;let num2 = -13;let num3 = -345;let num4 = 4.76;let num5 = 0;console.log(Math.abs(num1));console.log(Math.abs(num2));console.log(Math.abs(num3));console.log(Math.abs(num4));console.log(Math.abs(num5));``

To go out:

``32133454.760``

## 2. Math.cbrt ()

the cbrt () The method returns the cube root of a number.

``let num1 = 64;let num2 = 125;let num3 = -1;let num4 = Infinity;let num5 = 0;console.log(Math.cbrt(num1));console.log(Math.cbrt(num2));console.log(Math.cbrt(num3));console.log(Math.cbrt(num4));console.log(Math.cbrt(num5));``

To go out:

``45-1Infinity0``

## 3. Math.ceil ()

the ceiling() The method returns the next integer greater than or equal to a given number.

``let num1 = 34.5;let num2 = 54.234;let num3 = 7.0001;let num4 = 867.1;let num5 = 0;console.log(Math.ceil(num1));console.log(Math.ceil(num2));console.log(Math.ceil(num3));console.log(Math.ceil(num4));console.log(Math.ceil(num5));``

VIDEO OF THE DAY MAKEUSE

To go out:

``355588680``

## 4. Math.cos ()

the cos () The method returns the cosine of the specified angle. The given angle must be specified in radians.

``let num1 = 0;let num2 = 1;let num3 = Math.PI;let num4 = 0.5;let num5 = 45;console.log(Math.cos(num1));console.log(Math.cos(num2));console.log(Math.cos(num3));console.log(Math.cos(num4));console.log(Math.cos(num5));``

To go out:

``10.5403023058681398-10.87758256189037280.5253219888177297``

## 5. Math.cosh ()

the baton() The method returns the hyperbolic cosine of a number.

``let num1 = 0;let num2 = 1;let num3 = -1;let num4 = 2;let num5 = -2;console.log(Math.cosh(num1));console.log(Math.cosh(num2));console.log(Math.cosh(num3));console.log(Math.cosh(num4));console.log(Math.cosh(num5));``

To go out:

``11.54308063481524371.54308063481524373.76219569108363143.7621956910836314``

## 6. Math.exp (x)

the exp (x) the method returns e ^ x, where X is the argument, and e is the Euler number (also known as the Napier constant), the base of natural logarithms.

``let num1 = 0;let num2 = 1;let num3 = -1;let num4 = 2;let num5 = -2;console.log(Math.exp(num1));console.log(Math.exp(num2));console.log(Math.exp(num3));console.log(Math.exp(num4));console.log(Math.exp(num5));``

To go out:

``12.7182818284590450.367879441171442337.389056098930650.1353352832366127``

## 7. Math.floor ()

the stage() The method returns the next integer less than or equal to a given number.

``let num1 = 34.5;let num2 = 54.234;let num3 = 7.0001;let num4 = 867.1;let num5 = 0;console.log(Math.floor(num1));console.log(Math.floor(num2));console.log(Math.floor(num3));console.log(Math.floor(num4));console.log(Math.floor(num5));``

To go out:

``345478670``

Related: JavaScript Map Methods You Need To Master Today

## 8. Math.log ()

the Newspaper() The method returns the natural logarithm (base e) of a number.

``let num1 = 0;let num2 = 1;let num3 = -1;let num4 = 10;let num5 = -2;console.log(Math.log(num1));console.log(Math.log(num2));console.log(Math.log(num3));console.log(Math.log(num4));console.log(Math.log(num5));``

To go out:

``-Infinity0NaN2.302585092994046NaN``

## 9. Math.max (x, y, …)

the max () The method returns the highest value number from a list of numbers.

``let list1 = [24, 645, 678, Infinity];let list2 = [75, 12, 92, 8];let list3 = [2947, -435, -123, 0, -Infinity];console.log(Math.max(...list1));console.log(Math.max(...list2));console.log(Math.max(...list3));console.log(Math.max(1, 2, 3));console.log(Math.max(234, 46, -23));``

To go out:

``Infinity9229473234``

Related: JavaScript Bundle Methods You Must Master Today

## 10. Math.min (x, y, …)

the min () The method returns the lowest number in a list of numbers.

``let list1 = [24, 645, 678, Infinity];let list2 = [75, 12, 92, 8];let list3 = [2947, -435, -123, 0, -Infinity];console.log(Math.min(...list1));console.log(Math.min(...list2));console.log(Math.min(...list3));console.log(Math.min(1, 2, 3));console.log(Math.min(234, 46, -23));``

To go out:

``248-Infinity1-23``

## 11. Math.pow (x, y)

the pow (x, y) The method returns the base to the power of the exponent (x ^ y).

``console.log(Math.pow(1, 10));console.log(Math.pow(2, 4));console.log(Math.pow(1, Infinity));console.log(Math.pow(10, 10));console.log(Math.pow(-1, 3));``

To go out:

``116NaN10000000000-1``

## 12. Random Math ()

the Random() The method returns a random number between 0 and 1 (including 0, but not 1).

``console.log(Math.random());console.log(Math.random());console.log(Math.random());console.log(Math.random());console.log(Math.random());``

To go out:

``0.008825924668635520.119030115174533660.96891282693842350.84628632610134420.4431704664004701``

Related: JavaScript String Methods You Should Master Today

## 13. Math.round ()

the tower() The method returns the value of a number rounded to the nearest integer.

``let num1 = 34.5;let num2 = 54.234;let num3 = 7.0001;let num4 = 867.1;let num5 = 0;console.log(Math.round(num1));console.log(Math.round(num2));console.log(Math.round(num3));console.log(Math.round(num4));console.log(Math.round(num5));``

To go out:

``355478670``

## 14. Math.sin ()

the peach() The method returns the sine of the specified angle. The given angle must be specified in radians.

``let num1 = 0;let num2 = 1;let num3 = Math.PI;let num4 = 0.5;let num5 = 45;console.log(Math.sin(num1));console.log(Math.sin(num2));console.log(Math.sin(num3));console.log(Math.sin(num4));console.log(Math.sin(num5));``

To go out:

``00.84147098480789651.2246467991473532e-160.4794255386042030.8509035245341184``

## 15. Math.sinh ()

the sinh () The method returns the hyperbolic sine of a number.

``let num1 = 0;let num2 = 1;let num3 = -1;let num4 = 2;let num5 = -2;console.log(Math.sinh(num1));console.log(Math.sinh(num2));console.log(Math.sinh(num3));console.log(Math.sinh(num4));console.log(Math.sinh(num5));``

To go out:

``01.1752011936438014-1.17520119364380143.626860407847019-3.626860407847019``

## 16. Math.sqrt ()

the sqrt () The method returns the square root of a number.

``let num1 = 64;let num2 = 25;let num3 = -1;let num4 = Infinity;let num5 = 144;console.log(Math.sqrt(num1));console.log(Math.sqrt(num2));console.log(Math.sqrt(num3));console.log(Math.sqrt(num4));console.log(Math.sqrt(num5));``

To go out:

``85NaNInfinity12``

Related: One-Liners JavaScript You Need To Know

## 17. Math.tan ()

the tan () The method returns the tangent of a number.

``let num1 = 0;let num2 = 1;let num3 = Math.PI;let num4 = 0.5;let num5 = 45;console.log(Math.tan(num1));console.log(Math.tan(num2));console.log(Math.tan(num3));console.log(Math.tan(num4));console.log(Math.tan(num5));``

To go out:

``01.5574077246549023-1.2246467991473532e-160.54630248984379051.6197751905438615``

## 18. Math.tanh ()

the tanh () The method returns the hyperbolic tangent of a number.

``let num1 = 0;let num2 = 1;let num3 = -1;let num4 = 2;let num5 = -2;console.log(Math.tanh(num1));console.log(Math.tanh(num2));console.log(Math.tanh(num3));console.log(Math.tanh(num4));console.log(Math.tanh(num5));``

To go out:

``00.7615941559557649-0.76159415595576490.9640275800758169-0.9640275800758169``

## 19. Math.trunc (x)

the trunk (x) The method returns the integer part of x, removing any fractional digits.

``let num1 = 34.5;let num2 = 54.234;let num3 = 7.0001;let num4 = 867.1;let num5 = -0.7632;console.log(Math.trunc(num1));console.log(Math.trunc(num2));console.log(Math.trunc(num3));console.log(Math.trunc(num4));console.log(Math.trunc(num5));``

To go out:

``34547867-0``

If you’d like to check out the full source code used in this article, here’s the GitHub repository.

## Use array methods

Arrays are one of the most used data structures in programming. In addition to math methods, JavaScript also provides several built-in array methods such as to push(), concatenated (), to rejoin(), for each(), card(), sort (), etc. You can use all of these built-in methods to comfortably work with JavaScript tables.

15 JavaScript array methods you should master today

Want to understand JavaScript tables but can’t seem to master them? See our sample JavaScript tables for tips.