> For the complete documentation index, see [llms.txt](https://docs.angular-package.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.angular-package.dev/type/guard/guardnull.md).

# guardNull()

## `guardNull()`

Guards the value to be [`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null).

{% code title="guard-null.func.ts" %}

```typescript
const guardNull = <Payload extends object>(
  value: null,
  callback?: ResultCallback<null, Payload>,
  payload?: Payload
): value is null => isNull(value, callback, payload);
```

{% endcode %}

Code on [**GitHub**](https://github.com/angular-package/type/blob/5.0.x/src/guard/lib/guard-null.func.ts).

### Generic type variables

#### <mark style="color:green;">**`Payload`**</mark>**`extends`**<mark style="color:green;">**`object`**</mark>

The `Payload` generic type variable constrained by [`object`](https://www.typescriptlang.org/docs/handbook/basic-types.html#object) indicates the type of optional parameter [`payload`](/type/type/resultcallback.md#payload-payload) of the supplied [`callback`](#callback-resultcallback-less-than-null-payload-greater-than) function and [`payload`](#payload-payload) optional parameter of the [`guardNull()`](#guardnull) function from which it captures its value.

### Parameters

#### `value: null`

The value of [`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null) type to guard.

#### `callback?: ResultCallback<null, Payload>`

The optional callback [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions) of [`ResultCallback`](/type/type/resultcallback.md) type with parameters, the [`value`](#value-null) that has been checked, the [`result`](/type/type/resultcallback.md#result-boolean) of this check, and [`payload`](/type/type/resultcallback.md#payload-payload) of generic type variable [`Payload`](#payloadextendsobject) with optional properties from the provided [`payload`](#payload-payload), to handle them before the [`result`](/type/type/resultcallback.md#result-boolean) return. By default, it uses [`resultCallback()`](/type/helper/resultcallback.md) function.

#### `payload?: Payload`

An optional [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of the generic type variable [`Payload`](#payloadextendsobject) is assigned to the [`payload`](/type/type/resultcallback.md#payload-payload) of the given [`callback`](#callback-resultcallback-less-than-null-payload-greater-than) function.

### Return type

#### `value is null`

The **return type** is a [`boolean`](https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean) as the result of its statement indicating the [`value`](#value-null) is [`null`](https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined).

### Returns

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) indicating whether the [`value`](#value-null) is [`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null).

## Example usage

```typescript
// Example usage.
import { guardNull } from '@angular-package/type';

guardNull(null); // true, value is null
guardNull(undefined as any); // false, value is null
```
