Horje
JavaScript Program to Convert Radians to Degree

Radians and degrees are units of angular measurement used extensively in mathematics, physics, and engineering. Converting radians to degrees is a common operation in trigonometry and other mathematical calculations.

Example:

// Formula to convert radian into degree: 
degrees = radians × (180/π)
Where:
π is the mathematical constant equal to 3.14159.

Below are the approaches to convert radian to the degree in JavaScript:

Table of Content

Using Function

Here the code defines a function, convertRadiansToDegrees, that takes the radians as an input parameter for converting it into degrees. It then invokes the function with a radians value of π/4. Inside the function, use the formula: radians × (180/π), to convert it into degrees. Finally, return the result.

Example: The example below shows the demonstration of converting radians into degrees using a function.

JavaScript
function convertRadiansToDegrees(radians) {
    return radians * (180 / Math.PI);
}

const radians = Math.PI / 4; 
const degrees = convertRadiansToDegrees(radians);
console.log(`${radians} radians is equal to ${degrees} degrees.`);

Output
0.7853981633974483 radians is equal to 45 degrees.

Time Complexity: O(1)

Space Complexity: O(1)

Using Class

Here we will define a class named AngleConverter which will contain a method called convertToDegrees and will handle the conversion of radians to degrees. Instantiate the AngleConverter class using the new keyword, which creates an object of the class. Call the convertToDegrees method on the converter object, passing the angle in radians you want to convert as an argument. Print result.

Example: The example below shows the demonstration of converting radians into degrees using class.

JavaScript
class AngleConverter {
    convertToDegrees(radians) {
        return radians * (180 / Math.PI);
    }
}

const converter = new AngleConverter();
const radians = Math.PI / 4; 
const degrees = converter.convertToDegrees(radians);
console.log(`${radians} radians is equal to ${degrees} degrees.`);

Output
0.7853981633974483 radians is equal to 45 degrees.

Time Complexity: O(1)

Space Complexity: O(1)




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
JavaScript Program to Convert Kilometers to Miles JavaScript Program to Convert Kilometers to Miles
Check if Pair with Given Sum Exists in Array in JavaScript Check if Pair with Given Sum Exists in Array in JavaScript
How to Master JSON in JavaScript? How to Master JSON in JavaScript?
How to Compare Two Objects using Lodash? How to Compare Two Objects using Lodash?
How to do a Deep Comparison Between Two Objects using Lodash? How to do a Deep Comparison Between Two Objects using Lodash?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15