JavaScript Math asin() method is used to calculate the arcsine(in radians) of a number of a number.
Syntax
Math.asin(x)
Parameters
x(required): It is the number for which you want to calculate the arcsine. The number should be in the range of -1 to 1.
Return Value
Returns a numeric value between -pi/2 and pi/2 radians.
If the argument is either non-numeric or greater than 1, or less than -1, it returns NaN.
Visual Representation
Example 1: How to Use Math asin() Function
var a = 1; //positive number
var b = -1; //negative number
var c = 0.5; //floating number
var d = 0;
console.log(Math.asin(a));
console.log(Math.asin(b));
console.log(Math.asin(c));
console.log(Math.asin(d));
Output
1.5707963267948966
-1.5707963267948966
0.5235987755982989
0
Example 2:Handling Value Outside the -1 to 1 Range
var a = 2;
var b = -2;
console.log(Math.asin(a));
console.log(Math.asin(b));
Output
NaN
NaN
Example 3:Handling non-numeric and empty value
console.log(Math.asin("JavaScript")); //non-numeric value
console.log(Math.asin()); //empty value
Output
NaN
NaN
Browser Compatibility
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.