totn JavaScript

JavaScript: Math asin() function

This JavaScript tutorial explains how to use the math function called asin() with syntax and examples.

Description

In JavaScript, asin() is a function that is used to return the arc sine of a number, with the result expressed in radians. Because the asin() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the asin() function is:

Math.asin(number);

Parameters or Arguments

number
The number used to calculate the arc sine in radians. The number must be a value between 1 and -1.

Returns

The asin() function returns the arc sine of a number and the result is expressed in radians.

If the number is not within the range of -1 and 1, the asin() function will return NaN.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which asin() is one of these functions.

Example

Let's take a look at an example of how to use the asin() function in JavaScript.

For example:

console.log(Math.asin(0.75));
console.log(Math.asin(-0.9));
console.log(Math.asin(2));

In this example, we have invoked the asin() function using the Math class.

We have written the output of the asin() function to the web browser console log, for demonstration purposes, to show what the asin() function returns.

The following will be output to the web browser console log:

0.848062078981481
-1.1197695149986342
NaN

In this example, the first output to the console log returned 0.848062078981481 which is the arc sine of 0.75. The second output to the console log returned -1.1197695149986342 which is the arc sine of -0.9. The third output to the console log returned NaN since the number was not within the range of 1 and -1.

The result from the asin() function is expressed in radians.