ตัวแปรชนิดตรรก : Logical Values
JavaScript มีความสามารถในการเปลี่ยนชนิดตัวแปรโดยอัตโนมัติ ค่าตัวแปรชนิดที่เป็นตรรก คือ True และ False
จะถูกแทนที่ด้วยค่าอะไร ถ้ามันถูกเอามาใช้แบบเลขจำนวนเต็ม
ตัวอย่างต่อไปนี้จะแสดงให้เห็นว่า Boolean สามารถเปลี่ยนเป็น Integer
<html>
<head>
<title>Conversation of logical values to numeric values</title>
</head>
<body>
<script language="JavaScript">
<!--
document.write("true*5 + false *7 = ");
document.write(true*5 + false *7);
// -->
</script>
</body>
</html>
|