JavaScript 中布尔值的创建
<!DOCTYPE html><html lang="en"><body><script> // Create a Boolean object using the new keyword and the Boolean() constructor. var myBoolean1 = new Boolean(false); // Using new keyword. console.log(typeof myBoolean1); // Logs 'object'. // Create a Boolean literal/primitive by directly using the number constructor without new. var myBoolean2 = Boolean(0); // Without new keyword. console.log(typeof myBoolean2); // Logs 'boolean'. // Create Boolean literal/primitive (constructor leveraged behind the scenes). var myBoolean3 = false; console.log(typeof myBoolean3); // Logs 'boolean'. console.log(myBoolean1, myBoolean2, myBoolean3); // Logs false false false. </script></body></html>