JavaScript's remainder can be negative. Normalize a bearing into one full turn before choosing a compass label.
Worked example
const bearing = -35;
console.log(((bearing % 360) + 360) % 360);Result
325Implementation notes
Normalizing 360 to zero keeps lookup indices in bounds. If the UI prints 360 for north, make that a presentation choice after the calculation.
Try it yourself
Compare -1, 359, 360 and 721 degrees.
Open the JavaScript example →Editorial date August 17, 2026 · Published December 6, 2026