JavaScript - calculate cos in degrees

3 points
Created by:

In this article, we would like to show you a simple example of how to calculate cos in degrees in JavaScript.

In order to use this example we just need to change the value of deg variable to some other value (in degrees).

// ONLINE-RUNNER:browser;

function calculateCos(deg) {
	var rad = (Math.PI / 180) * deg;
  	return Math.cos(rad);

var deg = 30;
var y = calculateCos(deg);

// cos(30 deg) = 0.8660254037844387
console.log('cos(' + deg + ' deg) = ' + y);

We can change deg to other values.

Example of common calculations:

cos(0 deg) = 1
cos(30 deg) = 0.8660254037844387
cos(45 deg) = 0.7071067811865476
cos(60 deg) = 0.5000000000000001
cos(90 deg) = 6.123233995736766e-17

I've prepared a similar post but for calculation sin in degrees:

Alternative titles

  1. JavaScript - calculate cosine in degrees
  2. JavaScript - calculate cosinus in degrees
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - math (popular problems)

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂