Skip to content

Logic functions

Every function in this family, with its signature and examples. Each example runs as a test of the language. See Language basics for how calls, types, and operators work.

if

Returns the first value if the condition is true; otherwise, returns the second value.

if(condition: boolean, then: any, else: any) → any
  • if(true, 1, 2) gives 1
  • if(false, 1, 2) gives 2
  • true ? "Complete" : "Incomplete" gives "Complete"

ifs

Returns the value of the first true condition, or the last value when none is true, in place of nested if() calls.

ifs(condition: boolean, value: any, condition2: boolean, value2: any, …, else: any) → any
  • ifs(true, 1, true, 2, 3) gives 1
  • ifs(false, 1, true, 2, 3) gives 2
  • ifs(false, 1, false, 2, 3) gives 3

empty

Returns true if the value is empty; 0, "", and [] are empty.

empty(value: any) → boolean

Also callable as receiver.empty(…), with the receiver as the first argument.

  • empty(0) gives true
  • empty("") gives true
  • empty([]) gives true
  • "Notion".empty() gives false

equal

Returns true if both values are equal and false otherwise, the same as ==.

equal(a: any, b: any) → boolean

Also callable as receiver.equal(…), with the receiver as the first argument.

  • equal(1, 1) gives true
  • "a" == "b" gives false
  • "1" == 1 gives false
  • [1, 2] == [2, 1] gives false

unequal

Returns false if both values are equal and true otherwise, the same as !=.

unequal(a: any, b: any) → boolean

Also callable as receiver.unequal(…), with the receiver as the first argument.

  • unequal(1, 2) gives true
  • "a" != "a" gives false

and

Returns the logical AND of its two arguments.

and(a: boolean, b: boolean) → boolean

Also callable as receiver.and(…), with the receiver as the first argument.

  • and(true, false) gives false
  • true && true gives true
  • true and false gives false

or

Returns the logical OR of its two arguments.

or(a: boolean, b: boolean) → boolean

Also callable as receiver.or(…), with the receiver as the first argument.

  • or(true, false) gives true
  • false || false gives false
  • false or true gives true

not

Returns the logical NOT of its argument.

not(value: boolean) → boolean

Also callable as receiver.not(…), with the receiver as the first argument.

  • not(true) gives false
  • !false gives true
  • not true gives false

let

Binds a name to a value for the body expression, so a value computed once can be used several times.

let(name, value: any, body: any) → any
  • let(x, 10, x * 2) gives 20
  • let(word, "go", word + word) gives "gogo"

lets

Binds several names in order for the body expression; each value can use the names bound before it.

lets(name, value: any, name2, value2: any, …, body: any) → any
  • lets(a, 1, b, a + 1, a + b) gives 3