JavaScript Math.cosh()
Syntax & Examples
Math.cosh() static-method
The Math.cosh() method in JavaScript returns the hyperbolic cosine of a number (x). It is a static method of Math, meaning it is always used as Math.cosh() and not as a method of a Math object created (Math is not a constructor).
Syntax of Math.cosh()
The syntax of Math.cosh() static-method is:
Math.cosh(x)
This cosh() static-method of Math returns the hyperbolic cosine of x.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
x | required | A number for which to return the hyperbolic cosine. |
Return Type
Math.cosh() returns value of type Number
.
✐ Examples
1 Using Math.cosh() with a positive number
In this example, we use the Math.cosh()
method to find the hyperbolic cosine of 1.
For example,
- We call
Math.cosh()
with 1 as the argument. - The method returns the hyperbolic cosine of 1.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.cosh(1));
Output
1.5430806348152437
2 Using Math.cosh() with zero
In this example, we use the Math.cosh()
method to find the hyperbolic cosine of 0.
For example,
- We call
Math.cosh()
with 0 as the argument. - The method returns the hyperbolic cosine of 0.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.cosh(0));
Output
1
3 Using Math.cosh() with a negative number
In this example, we use the Math.cosh()
method to find the hyperbolic cosine of -1.
For example,
- We call
Math.cosh()
with -1 as the argument. - The method returns the hyperbolic cosine of -1.
- We log the result to the console using
console.log()
.
JavaScript Program
console.log(Math.cosh(-1));
Output
1.5430806348152437
Summary
In this JavaScript tutorial, we learned about cosh() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.