Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Math
  6. cos()

Math.cos()

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

TheMath.cos() static method returns the cosine of a number in radians.

Try it

function getCircleX(radians, radius) {  return Math.cos(radians) * radius;}console.log(getCircleX(1, 10));// Expected output: 5.403023058681398console.log(getCircleX(2, 10));// Expected output: -4.161468365471424console.log(getCircleX(Math.PI, 10));// Expected output: -10

Syntax

js
Math.cos(x)

Parameters

x

A number representing an angle in radians.

Return value

The cosine ofx, between -1 and 1, inclusive. Ifx isInfinity,-Infinity, orNaN, returnsNaN.

Description

Becausecos() is a static method ofMath, you always use it asMath.cos(), rather than as a method of aMath object you created (Math is not a constructor).

Examples

Using Math.cos()

js
Math.cos(-Infinity); // NaNMath.cos(-0); // 1Math.cos(0); // 1Math.cos(1); // 0.5403023058681398Math.cos(Math.PI); // -1Math.cos(2 * Math.PI); // 1Math.cos(Infinity); // NaN

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-math.cos

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp