JavaScript Boolean object

JavaScript Boolean (Boolean) Object

TBoolean (Boolean) object is used to convert non-Boolean values ​​to Boolean values ​​(true or false).

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-0null""falseundefinedNaN

Then the object's The value is false. Otherwise, its value is true (even when the argument is the string "false")!


Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭