ฟังก์ชัน cos() ของออบเจ็กต์ Math จะรับมุม (ในหน่วยเรเดียน) และคืนค่า cosine ของมุมนั้น
ไวยากรณ์
รูปแบบการใช้งานคือดังนี้
Math.cos(90)
ตัวอย่าง
<html> <head> <title>ตัวอย่าง JavaScript</title> </head> <body> <script type="text/javascript"> var result = Math.cos(90); document.write("ค่า cosine ของมุมที่ให้มา: "+result); </script> </body> </html>ผลลัพธ์
ค่า cosine ของมุมที่ให้มา: -0.4480736161291702