Global Variables and Constants

Learn how to use global variables and constants in WebAsemmbly.

The globals section is where we can import and export values in and out of WebAssembly modules. In a WebAssembly module, you can import either mutable or immutable values from JavaScript. Additionally, WebAssembly also supports wasmValue, an internal immutable value inside the WebAssembly module itself.

Let’s create a file called globals.wat and add the following contents to it:

Get hands-on with 1200+ tech skills courses.