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 July 2015.
Math.sin()
静态方法以弧度为单位返回一个数字的正弦值。
尝试一下
function getCircleY(radians, radius) {
return Math.sin(radians) * radius;
}
console.log(getCircleY(1, 10));
// Expected output: 8.414709848078965
console.log(getCircleY(2, 10));
// Expected output: 9.092974268256818
console.log(getCircleY(Math.PI, 10));
// Expected output: 1.2246467991473533e-15
语法
js
Math.sin(x)
参数
x
-
一个数值(以弧度为单位)。
返回值
描述
由于 sin()
是 Math
的静态方法,应该总是以 Math.sin()
的形式,而不是作为 Math
对象的方法来使用它(Math
不是构造函数)。
示例
使用 Math.sin()
js
Math.sin(-Infinity); // NaN
Math.sin(-0); // -0
Math.sin(0); // 0
Math.sin(1); // 0.8414709848078965
Math.sin(Math.PI / 2); // 1
Math.sin(Infinity); // NaN
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-math.sin |
浏览器兼容性
BCD tables only load in the browser