此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
Math.sin()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Math.sin() 静态方法以弧度为单位返回一个数字的正弦值。
In this article
尝试一下
function getCircleY(radians, radius) { return Math.sin(radians) * radius;}console.log(getCircleY(1, 10));// Expected output: 8.414709848078965console.log(getCircleY(2, 10));// Expected output: 9.092974268256818console.log(getCircleY(Math.PI, 10));// Expected output: 1.2246467991473533e-15语法
js
Math.sin(x)参数
x一个数值(以弧度为单位)。
返回值
x 的正弦值,介于 -1 到 1 之间(包含 -1 和 1)。如果x 为Infinity、-Infinity 或NaN,则返回NaN。
描述
由于sin() 是Math 的静态方法,应该总是以Math.sin() 的形式,而不是作为Math 对象的方法来使用它(Math 不是构造函数)。
示例
>使用 Math.sin()
js
Math.sin(-Infinity); // NaNMath.sin(-0); // -0Math.sin(0); // 0Math.sin(1); // 0.8414709848078965Math.sin(Math.PI / 2); // 1Math.sin(Infinity); // NaN规范
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.sin> |