What is Math.sin() in JavaScript?
In JavaScript, Math is a built-in object that contains different methods and properties used to perform mathematical operations. It contains a sin() function, which is used to compute the sine of a specified angle.
Syntax
Math.sin(param);
Parameter
param: This is the angle for which we want to compute the sine. Its type isNumberand it is measured in radians.
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
-
Number: It returns the sine of the given angle stored inparam. It is ofNumbertype. Its range is:- -1 <= result <= 1
-
NaN: The function returnsNaNifparamis positive or negativeInfinity.
To convert degrees to radians, use the following formula.
- Radians = Degrees x
π/180where
π= 3.14159, approximately.
Example
console.log("sin(-1) = " + Math.sin(-1));console.log("sin(0) = " + Math.sin(0));console.log("sin(1) = " + Math.sin(1));console.log("sin(∞) = " + Math.sin(Infinity));console.log("sin(-∞) = " + Math.sin(-Infinity));
Output
- sin ( -1 ) = -0.8414709848078965
- sin ( 0 ) = 0
- sin ( 1 ) = 0.8414709848078965
- sin ( ∞ ) = NaN
- sin ( -∞ ) = NaN