Most Common Javascript Math functions
These functions you need in your regular programming life
Math.abs(): This method returns the absolute (positive) value of a number. It takes one number parameter. If the number’s value is negative, the abs() method converted this number is positive. The positive parameter will remain the same.
Syntax: Math.abs(number)
Ex:
const number = -2;console.log(Math.abs(number));// Result: 2const number2 = (10–100);console.log(Math.abs(number2));// Result: 90const number3 = 40;console.log(Math.abs(number3));// Result: 40 . Remain same.
Math.sin(): This method returns the sine value of a number that calculates the trigonometry sine for the specified expression. It takes number as a parameter. If we pass another datatype it will return NaN.
Syntax: Math.sin(number)
Ex:
const number = 4;console.log(Math.sin(number));// Result: -0.7568024953079282console.log(Math.sin(‘Javascript’));//Result: NaN
Math.cos(): This method returns the cosine value of a number that calculates the trigonometry cosine for the specified expression. It takes a number as a parameter. If we pass another datatype it will return NaN.
Get Shrikanta Mazumder’s stories in your inbox
Join Medium for free to get updates from this writer.
Ex:
const number = 4;console.log(Math.cos(number));// Result: -0.6536436208636119console.log(Math.cos(‘Javascript’));//Result: NaN
Math.exp(): This javascript epx() function used to calculate the power of E. Where E is the Euler’s number approximately equal to 2.71828. It takes a number as an argument. If the argument is not a number it returns NaN.
Syntax: Math.exp(number)
Ex:
const num = 2;console.log(Math.exp(num));// Result: 7.38905609893065console.log(Math.exp(-2));// Result: 0.1353352832366127console.log(Math.exp(‘javascript’));// Result: NaN
Math.log(): This method returns the logarithmic value of a number that calculates the trigonometry logarithmic for the specified expression. It takes a number as a parameter. If we pass another datatype it will return NaN. If the parameter is 0, it returns negative infinity. When a parameter is a negative number or null, it will return NaN
Syntax: Math.log(number)
Ex:
const num = 2;console.log(Math.log(num));// Result: 0.6931471805599453console.log(Math.log(-1));// Result: NaNconsole.log(Math.log(0))// Result: -Infinity






