DEV Community


Posted on

Typescript for beginners: boolean

Boolean is the data type that has two possible values. It is either true or false.

To do type checking on the variable we can write a statement as follows

const isTrue : boolean = true;


  • Define variable const isTrue
  • Add typescript type check : boolean
  • Define value true

To check whether function is returning boolean we can do it as fallows:

function isOlder(age : number) : boolean {
  return age >= 18 ? true : false;

isOlder(18) // true
isOlder(16) // false
isOlder(true) // error 'Argument of type boolean is not assignable to parameter of type number'


  • Define function function isOlder(argument : typecheck) : type to return {...}

Top comments (0)