e01.org

local.tee: Wasm variable instruction

The local.tee variable instruction sets the value of a local variable and loads the value onto the stack.

The **`local.tee`** [variable instruction](/docs/WebAssembly/Reference/Variables) sets the value of a local variable and loads the value onto the stack.

The instruction is named after the T-splitter used in plumbing.

tabbed-taller

```wat interactive-example
(module
(import "console" "log" (func $log (param i32)))
(func $main

(local $var i32) ;; create a local variable named $var
(i32.const 10) ;; load `10` onto the stack
local.tee $var ;; set the $var to `10` and keep `10` on the stack
call $log ;; log the top item on the stack (10)

)
(start $main)
)
```

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

## Syntax

```wat
;; load the number 2 onto the stack
i32.const 2

;; store the number 2 in the variable $val and load it on the stack
local.tee $val
```

| Instruction | Binary opcode |
| ----------- | ------------- |
| `local.tee` | `0x22` |

## Specifications

## Browser compatibility

source: MDN Web Docs mirror · page

Cite this

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

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

Save to pass ·