bearingBetween() converts the incoming lats and lons to radians using degreesToRadians() for use in computing the y and x values, so re-applying it in the next to last line: var angle = degreesToRadians(atan2(y, x)); doesn't make any sense. Since the last line: return (angle + 360) % 360; is obviously handling degrees, it seems: var angle = radiansToDegrees(atan2(y, x)); would be correct.
bearingBetween() converts the incoming lats and lons to radians using degreesToRadians() for use in computing the y and x values, so re-applying it in the next to last line: var angle = degreesToRadians(atan2(y, x)); doesn't make any sense. Since the last line: return (angle + 360) % 360; is obviously handling degrees, it seems: var angle = radiansToDegrees(atan2(y, x)); would be correct.