WebAssembly.Global.prototype.value
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.
The value property of the WebAssembly.Global object prototype returns the value contained inside the global variable.
Value
A string indicating the value of the global.
Description
The value property of a Global object instance allows you to directly get or set the global's value.
For the setter to work, the global must be mutable (the mutable option was set to true when it was declared). If this is not the case, a TypeError exception is thrown.
Examples
>Creating a non-mutable global
js
const myGlobal = new WebAssembly.Global({ value: "i32", mutable: false }, 42);
// 42
console.log(myGlobal.value);
// TypeError
myGlobal.value = 100;
Creating a mutable global
js
const myGlobal = new WebAssembly.Global({ value: "i32", mutable: true }, 42);
// 42
console.log(myGlobal.value);
myGlobal.value = 100;
// 100
console.log(myGlobal.value);
Specifications
| Specification |
|---|
| WebAssembly JavaScript Interface> # dom-global-value> |
Browser compatibility
See also
globaldefinition- WebAssembly