GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

is_null: Wasm reference instruction

The ref.isnull reference instruction checks whether a reference is null.

The **`ref.is_null`** [reference instruction](/docs/WebAssembly/Reference/Reference) checks whether a reference is null.

tabbed-taller

```wat interactive-example
(module
(import "console" "log" (func $log (param i32)))
(func $f)
(elem declare func $f)
(func $main
ref.null func
ref.is_null
call $log ;; log 1: the reference is null

ref.func $f
ref.is_null
call $log ;; log 0: the reference isn't null
)
(start $main)
)
```

```js interactive-example
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
```

## WAT syntax

```plain
ref.is_null
```

- `ref.is_null`
- : The `ref.is_null` instruction.

### Immediates

None.

### Operand stack

```plain
[input:(ref null heap_type)] -> [output:i32]
```

- `input`
- : The reference to check. This can be a reference of any nullable reference type, for example a [`funcref`](/docs/WebAssembly/Reference/Value_types/funcref) or an [`externref`](/docs/WebAssembly/Reference/Value_types/externref).
- `output`
- : An [`i32`](/docs/WebAssembly/Reference/Value_types/i32) that is `1` if `input` is null, or `0` otherwise.

### Binary encoding

| Instruction | Binary format | Example text => binary |
| ------------- | ------------- | ----------------------- |
| `ref.is_null` | `0xd1` | `ref.is_null` => `0xd1` |

## Description

The `ref.is_null` instruction pops a reference off the stack and pushes `1` if it is null, or `0` if it isn't. It is typically used to check whether a nullable local, global or table element has been given a value yet, before using it with an instruction that would trap on a null reference.

To create a null reference, use [`ref.null`](/docs/WebAssembly/Reference/Reference/null). To convert a nullable reference into a non-nullable one, trapping if it is null, use [`ref.as_non_null`](/docs/WebAssembly/Reference/Reference/as_non_null).

## Specifications

## Browser compatibility

## See also

- [`ref.null`](/docs/WebAssembly/Reference/Reference/null)
- [`ref.as_non_null`](/docs/WebAssembly/Reference/Reference/as_non_null)
- [`ref.eq`](/docs/WebAssembly/Reference/Reference/eq)

source: MDN Web Docs mirror · page

Cite this

"is_null: Wasm reference instruction". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Reference/is_null

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·