JavaScript Math.cosh()

Posted by

Method

Introduction to JavaScript Math.cosh() Method

The JavaScript Math.cosh() method is a built-in function for computing the hyperbolic cosine of a number. The hyperbolic cosine of a number is defined as the sum of the hyperbolic series:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

cosh(x) = 1 + x2/2! + x4/4! + x6/6! + ...

[/dm_code_snippet]

The Math.cosh() method is a part of the Math object, which provides properties and methods for mathematical calculations.

Syntax

The syntax for the Math.cosh() method is given below:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

Math.cosh(x)

[/dm_code_snippet]

Here, x is the number for which you want to calculate the hyperbolic cosine.

Return Value

The Math.cosh() method returns the hyperbolic cosine of the given number.

Examples

Let’s look at some examples of using the Math.cosh() method.

Example 1: Calculating the Hyperbolic Cosine of a Number

In this example, we will use the Math.cosh() method to calculate the hyperbolic cosine of a number.

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

// Calculate the hyperbolic cosine of 10
let result = Math.cosh(10);

// Print the result
console.log(result);

[/dm_code_snippet]

When you run the above code, it will print the following result:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

11013.232920103323

[/dm_code_snippet]

Example 2: Calculating the Hyperbolic Cosine of a Negative Number

In this example, we will use the Math.cosh() method to calculate the hyperbolic cosine of a negative number.

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

// Calculate the hyperbolic cosine of -10
let result = Math.cosh(-10);

// Print the result
console.log(result);

[/dm_code_snippet]

When you run the above code, it will print the following result:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

11013.232920103323

[/dm_code_snippet]

As you can see, the Math.cosh() method returns the same value for a positive and negative number.

Conclusion

In this tutorial, we discussed the JavaScript Math.cosh() method. We looked at the syntax, return value, and examples of using this method. We also discussed how the Math.cosh() method returns the same value for a positive and negative number.