Truthy and falsy values

Rules for evaluating truthfulness of statements

Expanding on the Boolean data type, every other piece of data in Documotor can be evaluated in Boolean logic. We call the values that evaluate to true truthy, and the values that evaluate to false falsy.

The following values are falsy:

  • null
  • ""
  • "false"
  • false
  • 0 and all negative numbers
  • {}

All the other values are truthy. This is important for understanding the behavior of functions like if, or the Visibility binding. Namely, functions like these check if the argument is truthy or falsy, and then perform an action depending on that.

Examples

{
  true: if(`true`, 'truthy', 'falsy'),  // Returns 'truthy' if first argument is truthy, otherwise 'falsy'
  false: if(`false`, 'truthy', 'falsy'),
  emptyArray: if(`[]`, 'truthy', 'falsy'),
  zero: if(`0`, 'truthy', 'falsy'),
  one: if(`1`, 'truthy', 'falsy'),
  minusOne: if(`-1`, 'truthy', 'falsy'),
  charArray: if(`['a']`, 'truthy', 'falsy'),
  emptyObject: if(`{}`, 'truthy', 'falsy'),
  null: if(`null`, 'truthy', 'falsy'),
  falseString: if('false', 'truthy', 'falsy'), // string equal to 'false', not Boolean
  zeroString: if('0', 'truthy', 'falsy'),      // string equal to '0', not number
  object: if(`{"object": true}`, 'truthy', 'falsy'),
  nullString: if('null', 'truthy', 'falsy'),
  emptyString: if('', 'truthy', 'falsy')
}
{
  "true": "truthy",
  "false": "falsy",
  "emptyArray": "falsy",
  "zero": "falsy",
  "one": "truthy",
  "minusOne": "falsy",
  "charArray": "truthy",
  "emptyObject": "falsy",
  "null": "falsy",
  "falseString": "falsy",
  "zeroString": "truthy",
  "object": "truthy",
  "nullString": "truthy",
  "emptyString": "falsy"
}