Math.asin() finds the arc sine of a number in JavaScript. It helps you work with angles from values. You get the result in radians. JavaScript added Math.asin() to make math tasks easier.
Table of Content
It gives you a way to find angles from sine values. You use it in apps that need trigonometry.
What is Math.asin() in JavaScript?
Math.asin() function finds the angle whose sine equals the input. The input must be between -1 and 1. The result comes in radians. It returns NaN
if the input is outside the range. This function belongs to the Math object.
The syntax looks like this:
Math.asin(x)
x
: a number between -1 and 1- Returns: the angle in radians
Let me explain the details. JavaScript uses Math.asin() to trace a value back to its angle. It checks the sine table in reverse. The output gives you an angle in the range -π/2
to π/2
.
Use it to reverse a sine result. You need it when you already have the sine and want the angle.
Math.asin(0.5)
This code gives the arcsine of 0.5. The result is about 0.5236
radians. JavaScript reads the value, checks where it falls on the sine graph, and returns the matched angle in radians. It gives the only result possible within the set range.
Examples of JavaScript Math.asin()
Find arc sine of 0
Math.asin(0)
This returns 0
because sine of 0 equals 0. The function matches the input to the sine table and gives the angle that fits the sine value exactly.
Find arc sine of 1
Math.asin(1)
This returns about 1.5708
radians. That means the input matches the sine of π/2
. It gives the highest possible result that still fits inside the allowed range.
Find arc sine of -1
Math.asin(-1)
This gives about -1.5708
. JavaScript matches the input to the lowest sine value and returns the negative angle that fits the result.
Try a value outside the range
Math.asin(2)
This gives NaN
because 2 does not match any sine value. JavaScript only accepts values from -1 to 1. It returns NaN
for invalid input.
Use with Math.sin to get back the angle
Math.asin(Math.sin(Math.PI / 3))
This returns about 1.0472
, which matches the input angle in radians. JavaScript uses Math.sin to get the sine of π/3
then uses Math.asin to return the original angle.
Store result and convert to degrees
let rad = Math.asin(0.5);
let deg = rad * (180 / Math.PI);
This gives the angle in degrees. JavaScript first gets the radians from Math.asin() function. Then it multiplies by 180 and divides by π
to convert it.
Browser and JavaScript Version Support
Compatibility Across Browsers
- Works in Chrome
- Works in Firefox
- Works in Safari
- Works in Edge
- Works in Opera
All modern browsers support Math.asin(). You can use it without extra setup.
Support in Older JavaScript Versions
- Available in ECMAScript 1
- Works in all versions after ES1
Math.asin() function comes from the first version of JavaScript. It has support in all standard JavaScript engines. You can use it in old code or new code without worry.
Wrapping Up
In this article, you learned how to use JavaScript Math.asin().
Here’s a quick recap:
- Math.asin() finds the arc sine of a number
- It only works for values between -1 and 1
- The result comes in radians
- The return value shows the angle
- You can use it with Math.sin to reverse values
- Invalid inputs give
NaN
- You can convert the result to degrees
- It works in all major browsers
- It comes from early JavaScript versions