JavaScript Boolean (Boolean)
TBoolean (Boolean) object is used to convert non-Boolean values to Boolean values (true or false).
Online example
Checking Boolean value
Check whether the Boolean object is true or false.
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <script> var b1=new Boolean(0); var b2=new Boolean(1); var b3=new Boolean(""); var b4=new Boolean(null); var b5=new Boolean(NaN); var b6=new Boolean("false"); document.write("0 为布尔值 "+ b1 +"<br>"); document.write("1 为布尔值 "+ b2 +"<br>"); document.write("空字符串是布尔值 "+ b3 + "<br>"); document.write("null 是布尔值 "+ b4+ "<br>"); document.write("NaN 是布尔值 "+ b5 +"<br>"); document.write("字符串'false' 是布尔值"+ b6 +"<br>"); </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Complete Boolean Object Reference Manual
We provide the JavaScript Boolean Object Reference Manual, which includes all properties and methods available for Boolean objects.
This manual contains detailed descriptions and related examples of each property and method.
Create a Boolean object
The Boolean object represents two values: "true" or "false"
The following code defines a Boolean object named myBoolean :
var myBoolean=new Boolean();
If the Boolean object has no initial value or its value is:
0
- ##-0
- null
- ""
- false
- undefined
- NaN