Dùng Math.atan2(y, x) trả về góc (radian) giữa trục X dương và điểm (x,y), giá trị trong [-π, π].
Ví dụ
<html>
<head>
<title>Phương thức Math.atan2 trong JavaScript</title>
</head>
<body>
<script>
document.write("atan2(-1,1) = " + Math.atan2(-1,1) + "<br>"); // -π/4
document.write("atan2(0.5,1) = " + Math.atan2(0.5,1) + "<br>");
document.write("atan2(30,1) = " + Math.atan2(30,1) + "<br>");
document.write("atan2('text',1) = " + Math.atan2("Demo Text",1)); // NaN
</script>
</body>
</html>