Skip to main content

03 - Booleans

A Bool can be either true or false.

Motoko defines a handful of operators that work with Bools.

Logical operator and

false and false // => false
false and true  // => false
true and false  // => false
true and true   // => true

Logical operator or

false or false // => false
false or true  // => true
true or false  // => true
true or true   // => true

Logical operator not

Motoko supports negation of Bools either the not operator.

not true  // => false
not false // => true

Evaluation strategy

and and or are short circuiting, meaning they don't evaluate the right hand side if they don't have to.

and evaluates the right hand side if the left hand side is true.

or evaluates the right hand side if the left hand side is false.

Bool variables

You need to use type Bool to declare boolean variables:

let amILying : Bool = true;
let canIBeTrusted = false;

let shouldYouHireMe = not amILying and canIBeTrusted;
shouldYouHireMe