Skip to content

Commit afe159a

Browse files
committed
types-grammar, ch1: add text about boolean values
1 parent a390941 commit afe159a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

types-grammar/ch1.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,29 @@ The `= ..` clause on a parameter is referred to as the "parameter default". It o
164164
165165
The `boolean` type contains two values: `false` and `true`.
166166
167-
// TODO
167+
In the "old days", programming languages would, by convention, use `0` to mean `false` and `1` to mean `true`. So you can think of the `boolean` type, and the keywords `false` and `true`, as a semantic convenience sugar on top of the `0` and `1` values:
168+
169+
```js
170+
// isLoggedIn = 1;
171+
isLoggedIn = true;
172+
173+
isComplete = 0;
174+
// isComplete = false;
175+
```
176+
177+
Boolean values are how all decision making happens in a JS program:
178+
179+
```js
180+
if (isLoggedIn) {
181+
// do something
182+
}
183+
184+
while (!isComplete) {
185+
// keep going
186+
}
187+
```
188+
189+
The `!` operator negates/flips a boolean value to the other one: `false` becomes `true`, and `true` becomes `false`.
168190
169191
### String Values
170192

0 commit comments

Comments
 (0)