The boolean type in TypeScript

Hi in this post we are goin to see the “boolean” type in TypeScript and how can we use this type.

The boolean type only have 2 values: true or false.

We can compare them with ==, ===, ||, ? and negate them with !

Example:

let a = true; // a is boolean type

var b = false; // b is boolean type

const c = true; // c is true

let d: boolean = true; // d is boolean type

let e: true = true; // e is true

let f: true = false; // Error: Type 'false' is not assignable to type 'true'.

And in the following image we can see how the “f” is giving us a TypeScript error:

In general we use the first and second way to declare boolean types in our programs.

By Cristina Rojas.