boolean type
- TypeScript course
- Beginner
- Lesson 8/89
- 4 min
Learn boolean for logical values.
What is the boolean type?
The boolean type takes only two values: true or false. It is used to express a two-state condition such as on/off or yes/no.
let aktif: boolean = true;
let silindi: boolean = false;
console.log(aktif); // trueThe values are always written lowercase.
Boolean operations
boolean values can be combined with && (and), || (or), ! (not). Comparison results are also boolean.
let acik: boolean = true;
let kil: boolean = false;
console.log(acik && kil); // false
console.log(5 > 3); // truePractice Your first boolean variable
Declare a boolean variable named aktif and assign true. Then print its value with console.log.
Starter code
// aktif adında boolean değişken tanımla, true ata
// değeri yazdırSample solution
let aktif: boolean = true;
console.log(aktif);Expected output
true
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which of the following is a valid boolean variable declaration?
- let aktif: boolean = "true";
- let aktif: boolean = 1;
- let aktif: boolean = true; Correct answer
- let aktif: boolean = True;
Explanation: Only true or false (lowercase) can be assigned to a boolean variable; "true" is text, 1 is a number, and True is invalid.
2 Write the correct value
let aktif: boolean = ____;
let aktif: boolean = true;
Explanation: boolean values are written lowercase true or false; capital True is not valid.
3 boolean concepts
| Term | Meaning |
|---|---|
boolean |
two-state type |
true |
true value |
false |
false value |
: boolean |
type tag |