ฟังก์ชัน eval() ยอมรับค่าสตริงที่เก็บโค้ด JavaScript ฟังก์ชันนี้รันโค้ดที่กำหนดและส่งคืนผลลัพธ์ของโค้ด
ไวยากรณ์
ไวยากรณ์ของมันคือดังต่อไปนี้
eval(32*45);
ตัวอย่าง
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
document.write(eval(32*45));
document.write("<br>");
document.write(eval(new String("Hello welcome to Tutorialspoint")));
</script>
</body>
</html> ผลลัพธ์
1440 Hello welcome to Tutorialspoint