Math.sin(x) returns the sine of an angle measured in radians. If your input is in degrees, convert it to radians before calling Math.sin().
console.log(Math.sin(Math.PI / 2)); // 1
console.log(Math.sin(90 * Math.PI / 180)); // 1Math.sin(angleInRadians)Passing 90 directly means 90 radians, not 90 degrees. That is why Math.sin(90) is not 1.
console.log(Math.sin(90)); // about 0.8939966636console.log(Math.sin(0)); // 0
console.log(Math.sin(Math.PI / 2)); // 1
console.log(Math.sin(Math.PI)); // approximately 0
console.log(Math.sin(3 * Math.PI / 2)); // -1
console.log(Math.sin(2 * Math.PI)); // approximately 0function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
console.log(Math.sin(degreesToRadians(90))); // 1
console.log(Math.sin(degreesToRadians(270))); // -1Math.PI and the result are floating-point approximations. A tiny value such as 1.2246467991473532e-16 is effectively very close to zero but not represented as exact zero.
console.log(Math.sin(Infinity)); // NaN
console.log(Math.sin(NaN)); // NaNFor finite numeric inputs, the return value is between -1 and 1.
const angle = Math.PI / 6;
const radius = 10;
const y = Math.sin(angle) * radius;
console.log(y); // about 5
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.