bool and String
- Dart course
- Beginner
- Lesson 15/116
- 3 min
Learn bool and String types.
bool and String
The bool type has only two values: true and false. It is the basis of comparisons, conditions and flags.
String holds text. It is written with single quotes 'hello' or double quotes "hello"; both are the same.
Example: bool active = true; and String name = 'Alex';. You can print them with print.
Practice Declare bool and String
Declare bool active = true; and String name = 'Alex';. Print both with print.
Starter code
// Declare bool and StringSample solution
void main() {
bool active = true;
String name = 'Alex';
print(active);
print(name);
}Expected output
true Alex
Practice Combine and print
Declare bool active = true; and String name = 'Alex';. Print both on one line with print('$name $active').
Starter code
// Complete the programSample solution
void main() {
bool active = true;
String name = 'Alex';
print('$name $active');
}Expected output
Alex true
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is a valid bool value?
- yes
- true Correct answer
- 'true'
- 1
Explanation: true in lowercase is a bool value.
2 Boolean type
____ active = true;
bool active = true;
Explanation: bool holds true/false values.
3 bool and String concepts
| Term | Meaning |
|---|---|
bool |
Boolean |
String |
Text |
true |
True |
false |
False |