ฟังก์ชัน atan2() ของออบเจกต์ Math ยอมรับตัวเลขสองตัวที่แทนแกน y และ x และคืนค่ามุมระหว่างจุดที่กำหนดกับแกน x บวกในหน่วยเรเดียน หากต้องการแปลงค่าผลลัพธ์เป็นองศา ให้คูณด้วย 180 แล้วหารผลลัพธ์ด้วย 3.14159 (ค่า pi)
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
Math.atan2(10, 5)
ตัวอย่าง
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var result = Math.atan2(10, 5);
document.write("Hyperbolic arctangent value: "+result);
document.write("<br>");
document.write("Hyperbolic arctangent value in degrees: "+result*180/Math.PI);
</script>
</body>
</html> ผลลัพธ์
Hyperbolic arctangent value: 1.1071487177940904 Hyperbolic arctangent value in degrees: 63.43494882292201