From MiniScript Wiki
Revision as of 21:20, 15 February 2024 by JoeStrout (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

null is a keyword that represents the null value in MiniScript.

null is treated as false

null is considered false in if or while conditions, as well as in logical operations and, or, and not. For example, 1 and null evaluates to 0, while not null evaluates to 1.

Numeric arithmetic with null is null

When null is involved in any numeric expression, the result is null. For example, null + 42 is null.

null converts to an empty string

When null is added to a string, or explicitly converted to a string with str, it behaves the same as the empty string, "".

The exception to this is the standard print function; print null will actually print the string “null” rather than printing an empty string.

null coalescing

There is no built-in null-coalescing operator (i.e., an operator to select the first non-null value of two operands) in MiniScript. However, one could define a function for this purpose as follows.

ifNull = function(possiblyNullValue, defaultValue)
   if possiblyNullValue == null then return defaultValue else return possiblyNullValue
end function

Once defined, then print ifNull(x, "nothing") would print “nothing” when x is null, or the value of x otherwise.