-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathboolean.jsdoc
More file actions
77 lines (55 loc) · 1.49 KB
/
Copy pathboolean.jsdoc
File metadata and controls
77 lines (55 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Boolean : Object
A true or false value.
Primitive:
true
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.6
----
Boolean(value : Object) : Boolean
Coerces **value** into a boolean value. You can also use **!!value** to
do the coercion. Note **'false'** coerces to **true** since it is a non-empty
string. Use **value === 'true'** to convert a string to a Boolean.
<example>
console.log(Boolean(''));
console.log(Boolean('0'));
console.log(Boolean(0));
console.log(Boolean(1));
console.log(Boolean([]));
console.log(Boolean(undefined));
console.log(!!undefined);
console.log();
var stringToBoolean = function(value) {
return value === 'true';
};
console.log(Boolean('false'));
console.log(stringToBoolean('false'));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.1
----
new Boolean(value : Object) : Object
Creates a box for a boolean value.
<example>
var literal = true;
var boxed = new Boolean(true);
console.log(literal === true);
console.log(boxed === true);
console.log(boxed.valueOf() === true);
console.log();
// Literals cannot hold other properties but boxes can
literal.foo = 'bar';
boxed.foo = 'bar';
console.log(literal.foo);
console.log(boxed.foo);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.2
----
prototype.toString() : String
Returns a string representation of **this**.
<example>
console.log(true.toString());
console.log(false.toString());
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.6.4.2