Table of Content
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.
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
Click a button on a website. Something changes. A menu opens or a message pops up. That’s how JavaScript works.…
The "do while" loop in JavaScript runs code once before checking the condition. Use it when the code must run…
You have to organize your JavaScript code structure. A clean layout helps you read and fix your code. Whether you…
The ternary operator in JavaScript keeps your code short. It helps you write conditions inside one line. JavaScript lets you…
You use loops in JavaScript to repeat code without copying it many times. This helps when you handle lots of…
Arrow function gives you short code and keeps this in the right scope in JavaScript. Understand the Arrow Function in…
JavaScript arithmetic operators let you add, subtract, multiply, or divide numbers. You can also use them to find remainders or…
You may need to loop through properties when you work with objects in JavaScript. The for...in loop helps you do…
The JavaScript console is a tool in web browsers that helps you print the result to the web browser. It…
The Math.pow() function in JavaScript solves one common task. It raises a number to a power. This helps avoid loops…