Skip to main content

Logical Operators

These operations can be performed on boolean values.

Unary Operators

NOT (!)

Used to invert a boolean value; true values become false and false values become true.

knot
const foo = true;
const bar = false;
!foo == false;
!false == true;
!(foo && bar) == true;
knot
const foo = true;
const bar = false;
!foo == false;
!false == true;
!(foo && bar) == true;

Binary Operators

AND (&&)

This operation evaluates to true if both the left-hand and right-hand expressions evaluate to true and false otherwise.

knot
const foo = true;
const bar = false;
(foo && true) == true;
(bar && true) == false;
(bar && bar) == false;
knot
const foo = true;
const bar = false;
(foo && true) == true;
(bar && true) == false;
(bar && bar) == false;

OR (||)

This operation evaluates to true if either the left-hand or right-hand expressions evaluate to true and false otherwise.

knot
const foo = true;
const bar = false;
(foo || true) == true;
(bar || true) == true;
(bar || bar) == false;
knot
const foo = true;
const bar = false;
(foo || true) == true;
(bar || true) == true;
(bar || bar) == false;