JavaScript Math.sin()

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)); // 1

Math.sin() syntax Top ↑

Math.sin(angleInRadians)

Math.sin() expects radians, not degrees Top ↑

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.8939966636

Common angles in radians Top ↑

console.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 0

Convert degrees to radians Top ↑

function degreesToRadians(degrees) {
  return degrees * (Math.PI / 180);
}
console.log(Math.sin(degreesToRadians(90)));  // 1
console.log(Math.sin(degreesToRadians(270))); // -1

Why sin(π) may not display exactly 0 Top ↑

Math.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.

Return range and invalid inputs Top ↑

console.log(Math.sin(Infinity)); // NaN
console.log(Math.sin(NaN));      // NaN

For finite numeric inputs, the return value is between -1 and 1.

Using sine for circular movement Top ↑

const angle = Math.PI / 6;
const radius = 10;
const y = Math.sin(angle) * radius;
console.log(y); // about 5

Math.abs()




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer