ในการตรวจสอบว่าตัวแปรบูลีนใน JavaScript หรือไม่ ให้ใช้ตัวดำเนินการ typeof
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อตรวจสอบตัวแปรบูลีน -
<html>
<head>
<title>JavaScript Boolean</title>
</head>
<body>
<script>
var answer = true;
if(typeof(answer) === "boolean") {
alert("Boolean");
} else {
alert("Not a Boolean");
}
</script>
</body>
</html>