Arguments Object คืออาร์กิวเมนต์ที่ส่งเข้าฟังก์ชัน เป็นตัวแปรที่เข้าถึงได้ในทุกฟังก์ชัน สมมติส่งอาร์กิวเมนต์ 2 ตัว เข้าถึงได้ดังนี้
arguments[0] arguments[1]
สามารถใช้ typeof กับ Arguments ได้ เช่นกัน เริ่มจากดูการทำงานของ typeof ซึ่งเป็น Unary Operator วางก่อนตัวถูกดำเนินการได้ทุกประเภท
ตัวอย่าง typeof
<html>
<body>
<script>
var a = 20;
var b = "String";
var linebreak = "<br />";
result = (typeof b == "string" ? "B is String" : "B is Numeric");
document.write("Result => ");
document.write(result);
document.write(linebreak);
result = (typeof a == "string" ? "A is String" : "A is Numeric");
document.write("Result => ");
document.write(result);
document.write(linebreak);
</script>
</body>
</html>
typeof arguments จะคืนค่า Object สำหรับอาร์กิวเมนต์แต่ละตัว ใช้ได้ดังนี้
document.write(typeof arguments[0]); document.write(typeof arguments[1]);