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
Can I use Math asin with degrees?
What happens if the input is not a number?
Does Math asin work in all browsers?
How is Math asin different from Math.sin?
Similar Reads
Code mistakes used to slip by without a warning. That made bugs hard to trace and fix. JavaScript "use strict"…
The assignment operator in JavaScript stores and updates values. It helps you hold data in a variable and change it…
The JavaScript console is a tool in web browsers that helps you print the result to the web browser. It…
JavaScript gives you the Math.trunc() function to work with decimal numbers. You use it when you want to remove the…
Arrays often hold other arrays. This happens with API responses, form data, or nested objects. These layers add extra steps…
JavaScript Ninja Code points to ways that help a person write code that runs fast and stays easy to read.…
The ternary operator in JavaScript keeps your code short. It helps you write conditions inside one line. JavaScript lets you…
The toString function in JavaScript converts a value to a string form without change. It works on numbers, arrays, and…
JavaScript arithmetic operators let you add, subtract, multiply, or divide numbers. You can also use them to find remainders or…
AJAX keeps your web app fast. You do not need to reload the page every time you send or get…