# Math.sin()

> The `Math.sin()` static JS method returns the sine of a given number in radians.

## How do I use Math.sin() for animation in JavaScript?

The static method that returns the sine of a given number in radians. The result is a value between -1 and 1. For example, `Math.sin(Math.PI / 2)` returns 1.

- Topic: Math
- Type: method
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```js
const t = Date.now();
const y = Math.sin(t) * amplitude;
```

Right:

```js
const t = performance.now() / 1000;
const y = Math.sin(2 * Math.PI * frequency * t) * amplitude;
```

Raw milliseconds as radians change the phase too fast, while seconds times `2π * frequency` give a smooth wave.

## Common mistakes

- Passing degrees, like `Math.sin(90)`, and getting 0.894 instead of 1.
- Passing raw `Date.now()` and getting a wave that jumps randomly each frame.

## Key points

- Code converts degrees to radians with `deg * Math.PI / 180` before the call.
- Time-based waves divide milliseconds by 1000 and multiply by `2 * Math.PI * frequency`.

## Interview questions

### Why is Math.sin(Math.PI) not 0?

`Math.PI` is not exact, so the result is a tiny number like 1.22e-16. Compare with a tolerance.

### Does Math.sin() take degrees?

No. It takes radians, so convert with `deg * Math.PI / 180`.

## Related cards

- [Math.cos()](https://wonderium.dev/js/math-cos.md)
- [Math.asin()](https://wonderium.dev/js/math-asin.md)
- [Math.PI](https://wonderium.dev/js/math-pi.md)
- [requestAnimationFrame()](https://wonderium.dev/js/request-animation-frame.md)
- [sin()](https://wonderium.dev/css/sin.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/math-sin
- Last updated: 2026-11-25
