AppDividend
Latest Code Tutorials

Javascript Math sinh() Function Example

0

If you want to find the hyperbolic sine value of a given argument in JavaScript, then use the Math.sinh() method is used. The Math.sinh() method comes handy in programming contexts dealing with any trigonometric expressions. The sinh() is a static method of Math, and it can be used without creating an object.

Javascript Math sinh()

Javascript Math.sinh() function returns the hyperbolic sine of a number that can be expressed using the constant e.

Syntax

Math.sinh(x)

Parameter(s)

The variable x, whose hyperbolic sine value is to be determined.

Return Value

A number which is the hyperbolic sine value.

Polyfill

Math.sinh = Math.sinh || function(x) {
      return (Math.exp(x) - Math.exp(-x))/2;
};

OR,

Math.sinh = Math.sinh || function(x) {
      var y = Math.exp(x);
      return (y-1/y)/2;
};

See the following figure.

 

Javascript Math sinh()

Note

  • If the passed value is not a valid number, the method returns NaN.

Compatibility(Version and above)

  1. Google Chrome v38
  2. Firefox v25
  3. Edge v12
  4. Opera v25 
  5. Safari v8
  6. Android webview v38
  7. Chrome for Android v38
  8. Firefox for Android v25
  9. Opera for Android v25
  10. Safari on iOS v8
  11. Samsung Internet v3.0
  12. Node.js v0.12

Non-compatible with: Internet Explorer

JavaScript version: ECMAScript 6

Consider the following examples.

Javascript Math.sinh() function example

The following code shows the use of the Math.sinh() method.

// app.js

let a = 1;
let b = -1;
let c = 0;
let d = 4;
let e = -2;
let f = 2;


console.log(Math.sinh(a));
console.log(Math.sinh(b));
console.log(Math.sinh(c));
console.log(Math.sinh(d));
console.log(Math.sinh(e));
console.log(Math.sinh(f));

Output

node app
1.1752011936438014
-1.1752011936438014
0
27.28991719712775
-3.626860407847019
3.626860407847019

Example 2

The following code demonstrates the case where values other than valid numbers are passed.

// app.js

let a = "Hello, world";
let b;

console.log(Math.sinh(a));
console.log(Math.sinh(b));

Output

node app
NaN
NaN

Example 3

Javascript sinh() method cannot be used with complex arguments as only integer arguments are accepted. See the following code.

// app.js

// Complex values cannot be passed as arguments as follows
// Since only integer arguments are accepted.

console.log(Math.sinh(2 + i));

Output

node app
ReferenceError: i is not defined

Example 4

The following code demonstrates the use of Polyfill for the Math.sinh() method.

// app.js

let a = 1;
let b = -1;
let c = 0;
let d = 4;
let e = -2;
let f = 2;


function polyfill1(x) {
  return (Math.exp(x) - Math.exp(-x)) / 2;
}


function polyfill2(x) {
  var y = Math.exp(x);
  return (y - 1 / y) / 2;
}


console.log(Math.sinh(a));
console.log(Math.sinh(b));
console.log(Math.sinh(c));
console.log(Math.sinh(d));
console.log(Math.sinh(e));
console.log(Math.sinh(f));
console.log();


console.log(polyfill1(a));
console.log(polyfill1(b));
console.log(polyfill1(c));
console.log(polyfill1(d));
console.log(polyfill1(e));
console.log(polyfill1(f));
console.log();


console.log(polyfill2(a));
console.log(polyfill2(b));
console.log(polyfill2(c));
console.log(polyfill2(d));
console.log(polyfill2(e));
console.log(polyfill2(f));

Output

node app
1.1752011936438014
-1.1752011936438014
0
27.28991719712775
-3.626860407847019
3.626860407847019

1.1752011936438014
-1.1752011936438014
0
27.28991719712775
-3.626860407847019
3.626860407847019

1.1752011936438014
-1.1752011936438014
0
27.28991719712775
-3.6268604078470186
3.626860407847019

See also

Javascript Math max()

Javascript Math exp()

Javascript Math pow()

Javascript Math tanh()

Javascript Math sqrt()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.