คุณสมบัติคอนสตรัคเตอร์บูลีนส่งคืนฟังก์ชันคอนสตรัคเตอร์ที่สร้างต้นแบบบูลีน -
ต่อไปนี้เป็นรหัสสำหรับคุณสมบัติตัวสร้างบูลีนจาวาสคริปต์ -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>JavaScript Boolean constructor Property</h1>
<p class="sample"></p>
<button class="btn">CLICK HERE</button>
<h3>Click on the above button to get the boolean constructor function</h3>
<script>
var bool = true;
document.querySelector(".btn").addEventListener("click", () => {
document.querySelector(".sample").innerHTML =
"The boolean constructor function: <br>" + bool.constructor;
});
</script>
</body>
</html> ผลลัพธ์

เมื่อคลิกปุ่ม “คลิกที่นี่” -
