Top community members
All Wiki Articles Create Wiki Article

In the past we had a dream,
to have place where we could share IT knowledge,
to ask questions without fear that someone will judge us.

Now we are a group of people who make this dream come true. ❤ 💻

If you think sharing knowledge and helping other is valuable.

join our community - Click here

JavaScript - Math.sin in degrees

0 contributions
5 points

In JavaScript Math.sin() method works using radians by default. To switch it to degrees some simple operation is necessary ((Math.PI / 180) * degrees). In this article we can see custom Math.sin() function that works on degrees.

// ONLINE-RUNNER:browser;

function calculateSine(deg) {
	var radians = (Math.PI / 180) * deg;
  
  	return Math.sin(radians);
}

// Example:

console.log( calculateSine(0)   ); //  0
console.log( calculateSine(30)  ); // ~0.5
console.log( calculateSine(45)  ); //  0.7071067811865475
console.log( calculateSine(60)  ); //  0.8660254037844386
console.log( calculateSine(90)  ); //  1

console.log( calculateSine(180) ); // ~0
console.log( calculateSine(270) ); // -1
console.log( calculateSine(360) ); // ~0

See also

  1. JavaScript - Math.sin() method example
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more