Expand

null

is a constant representing absence of a value. null is a default value for unset variables.

Even though null looks like a bareword, it is not, because it's one of the exceptional words along with true and false.

null is serialized as null
/bin/echo null # => null
null is a default value for unset options
fn opt-test --opt $opt {
    put $opt       
}

opt-test            # => null
opt-test --opt 1    # => 1
opt-test --opt null # => null
null == null is true
fn arg-test $arg? {
    if $arg == null {
        print "Not set"
    } else {
        print $arg
    }
}

arg-test       # => Not set
arg-test null  # => Not set
arg-test abc   # => abc
?? is useful to replace null with a predefined value
fn arg-test $arg? {
    print ($arg ?? "Not set")
}

arg-test       # => Not set
arg-test null  # => Not set
arg-test abc   # => abc
null can't start bareword, use quotes
print  null/x  # syntax error
print "null/x" # OK

See Also