How to convert degrees to radians in JavaScript

Converting degrees to radians is crucial for trigonometric functions, mathematical calculations, animation rotations, and implementing features like canvas graphics or geometric transformations in JavaScript applications. With over 25 years of experience in software development and as the creator of CoreUI, I’ve implemented degree-to-radian conversion in components like chart rotations, animation systems, and mathematical utilities where JavaScript’s trigonometric functions require radian input for accurate calculations. From my extensive expertise, the standard mathematical approach is multiplying degrees by π/180, using JavaScript’s Math.PI constant for precision. This conversion is essential since JavaScript’s trigonometric functions (sin, cos, tan) expect radian values rather than degrees.

Multiply degrees by π/180 to convert to radians.

const degrees = 90
const radians = degrees * (Math.PI / 180)
// Result: 1.5707963267948966 (π/2)

const degreesToRadians = (deg) => deg * (Math.PI / 180)
// Usage: degreesToRadians(180) returns π (3.141592653589793)

The conversion formula degrees * (Math.PI / 180) is based on the mathematical relationship that 180 degrees equals π radians. In this example, 90 degrees converts to π/2 radians (approximately 1.57), which is the correct input for Math.sin(radians) to return 1. The function version provides a reusable converter for any degree value. Common conversions: 90° = π/2 radians, 180° = π radians, 360° = 2π radians. This conversion is necessary because JavaScript’s Math.sin(), Math.cos(), and Math.tan() functions require radian inputs.

Best Practice Note:

This is the same approach we use in CoreUI components for trigonometric calculations, animation rotations, and geometric transformations across our component library. Create a utility function for reusability: const toRadians = deg => deg * Math.PI / 180. Always convert degrees to radians before using trigonometric functions. The inverse conversion uses radians * (180 / Math.PI). This conversion is fundamental for any application involving angles, rotations, or trigonometric calculations in JavaScript.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author