A Singapore Government Agency Website

Boolean

A logical data type that represents one of two possible values: true or false.

Operators


Logical operators

  • Conjunction: a and b
  • Disjunction: a or b
  • Negation: not a or not(a)

Note: Use and, or, and not — not &&, ||, or !.

Comparison operators

  • Equality: a == b
  • Inequality: a != b

Ternary operator

You can use the ternary operator to write compact, inline conditional expressions in the format: condition ? trueValue : falseValue.

product.price > 100 ? 'premium' : 'value'; // if price is greater than 100 "premium" otherwise "value"

Null coalescing operator

The ?? operator returns the right-hand value when the left-hand value is null. It can be chained.

customer.nickname ?? 'Guest';                           // "Guest" if nickname is null
customer.nickname ?? customer.firstName ?? 'Guest';     // chainable

Functions


bool

Convert the input into a boolean value; an error is thrown if the conversion is not possible.

bool('true'); // true
bool('false'); // false

type

Returns the type of the given value as a string.

type(42);          // "number"
type("hello");     // "string"
type(true);        // "bool"
type([1, 2, 3]);   // "array"
Chat with me!
Bot Launcher