JavaScript Math sin() method is used to calculate the sine of a number. The input number is expected to be in radians, not degrees.
Syntax
Math.sin(x)
Parameter(s)
x(required): It is a number whose sine value is to be determined.
Return Value
Returns a numeric value between -1 and 1 representing the sine of the angle given in radians.
If the parameter is not numeric or if an empty value is passed, it returns NaN.
Visual Representation
Example 1: How to Use Math sin() Method
let a = 8; //positive value
let b = 4;
let c = -8; //negative value
let d = 0;
console.log(Math.sin(a));
console.log(Math.sin(b));
console.log(Math.sin(c));
console.log(Math.sin(d));
Output
0.9893582466233818
-0.7568024953079282
-0.9893582466233818
0
Example 2: Passing an empty and non-numeric value
console.log(Math.sin()); //empty value
console.log(Math.sin("AppDividend")); //non-numeric value
Output
NaN
NaN
Example 3: Passing Pi as an argument
console.log(Math.sin(Math.PI));
console.log(Math.sin(Math.PI / 6)); //30 degrees
console.log(Math.sin(Math.PI / 4)); //45 degrees
console.log(Math.sin(Math.PI / 2)); //90 degrees
Output
1.2246467991473532e-16
0.49999999999999994
0.7071067811865475
1
Browser compatibility
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above