CodeBlanks Logo Icon CodeBlanks

bool and String

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

main.dart
// Declare bool and String

Sample solution

main.dart
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

main.dart
// Complete the program

Sample solution

main.dart
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

Question
____ active = true;
Answer
bool active = true;

Explanation: bool holds true/false values.

3 bool and String concepts

Term Meaning
bool Boolean
String Text
true True
false False

All lessons in Beginner