CodeBlanks Logo Icon CodeBlanks

boolean type

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);  // true

The 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);  // true

Practice Your first boolean variable

Declare a boolean variable named aktif and assign true. Then print its value with console.log.

Starter code

index.ts
// aktif adında boolean değişken tanımla, true ata

// değeri yazdır

Sample solution

index.ts
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

Question
let aktif: boolean = ____;
Answer
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

All lessons in Beginner