Function isNull

  • Checks if a value is null.

    Parameters

    • value: unknown

      The value to check.

    Returns value is null

    true if the check passes, false otherwise.

    Example

    Basic usage

    isNull(null) // true
    isNull(undefined) // false
    isNull(0) // false

    Type narrowing

    const value: string | null

    if (isNull(value)) {
    value // type: null
    } else {
    value // type: string
    }

    // or
    if (!isNull(value)) {
    value // type: string
    } else {
    value // type: null
    }

    Paired with assert

    import { assert, isNull } from 'uft'

    const token: string | null
    assert(!isNull(token), 'received null token')
    token // type: string

Generated using TypeDoc