JavaScript Math asin: How it Works with Examples

math.asin in javascript

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

It returns the arc sine of a number in radians. The value must be between -1 and 1. If the number is outside this range, it returns NaN. The angle always falls between -π/2 and π/2.

Can I use Math asin with degrees?

No. Math asin only gives results in radians. If you want degrees, you must convert the output. Multiply the result by 180 / Math.PI to get the angle in degrees.

What happens if the input is not a number?

JavaScript tries to convert the input to a number. If the result is not valid or not in range, Math.asin returns NaN. Always check the input before you call it.

Does Math asin work in all browsers?

Yes. It works in all modern browsers. It also works in older ones that follow ECMAScript 1 or later. You do not need to add anything extra.

How is Math asin different from Math.sin?

Math.sin gives the sine of an angle. Math.asin does the reverse. It takes a sine value and gives the angle. You use them together to go back and forth between angles and sine values.

Similar Reads

Assignment Operator in JavaScript with Examples

The assignment operator in JavaScript stores and updates values. It helps you hold data in a variable and change it…

JavaScript Syntax: The Complete Cheat Sheet

JavaScript syntax is what you will use when writing and reading javascript code, it is the foundation of using this…

JavaScript “use strict” Mode: What It Is and Why You Should Use It

Code mistakes used to slip by without a warning. That made bugs hard to trace and fix. JavaScript "use strict"…

JavaScript toString Function: How it Works with Examples

The toString function in JavaScript converts a value to a string form without change. It works on numbers, arrays, and…

JavaScript Class and Object Constructors with Examples

Object constructors and class constructors in JavaScript create objects in a structured way. Both provide methods to build reusable code.…

Data Types in JavaScript: Primitive and Non-Primitive

Data types in JavaScript help hold values and shape code rules. They set clear plans for text, numbers, and other…

JavaScript switch Statement: Syntax and Examples

JavaScript switch statement checks many values without long chains. It appeared to replace stacked conditions that slow you down. Understand…

Mocha JavaScript Test Framework: Guide and Examples

Mocha is a JavaScript test framework for Node.js. It runs tests in sequence and shows results. It works with any…

Print in JavaScript Console Using Log, Info, Warn, and Error

The JavaScript console is a tool in web browsers that helps you print the result to the web browser. It…

JavaScript Unary Operators: How they Work with Examples

Unary operators in JavaScript work with only one value. They can change, test, or change the type of that value,…

Previous Article

PHP For Loop: Run Code Using a Counter with Examples

Next Article

PHP Ternary Operator: How to Write Short Expressions

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.