---
title: "toBeNull() | Grafana k6 documentation"
description: "Asserts that a value is null"
---

# toBeNull()

The `toBeNull()` method asserts that a value is exactly `null`.

## Syntax

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
expect(actual).toBeNull();
expect(actual).not.toBeNull();
```

## Returns

Expand table

| Type | Description     |
|------|-----------------|
| void | No return value |

## Description

The `toBeNull()` method checks if a value is exactly `null`. It only passes for the `null` value and fails for all other values, including `undefined`, `false`, `0`, and empty strings.

## Usage

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import http from 'k6/http';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';

export default function () {
  const response = http.get('https://quickpizza.grafana.com/');

  // Check for null values in response
  const maybeNull = null;
  if (maybeNull === null) {
    expect(maybeNull).toBeNull();
  }

  // Check that required fields are not null
  expect(response.body).not.toBeNull();
  expect(response.status).not.toBeNull();

  // Basic null checks
  expect(null).toBeNull();
  expect(undefined).not.toBeNull();
  expect(false).not.toBeNull();
  expect(0).not.toBeNull();
}
```
