Practice WebAssembly JavaScript interop vocabulary: WASM exports, calling WASM functions from JS, shared memory, glue code, and wasm-bindgen for Rust-to-JS bindings.
0 / 5 completed
1 / 5
'The WASM module exports functions to JavaScript.' How does a WebAssembly module expose functionality to JS?
A WebAssembly module has an exports section that lists the functions, memory, and globals it makes available to the host environment (JavaScript). After instantiating the module (WebAssembly.instantiate), JS accesses exported functions via instance.exports.myFunction(). This explicit export mechanism is part of WASM's security model — only intentionally exported items are accessible.
2 / 5
'Calling a WASM function from JS: wasmModule.myFunction()'. What data types can be passed between JS and WASM?
The WASM-JS boundary natively supports only numeric types: i32, i64, f32, f64 (and more recently externref for JS object references). Passing strings, arrays, or objects requires copying data into the WASM linear memory (a shared ArrayBuffer) and passing a pointer + length. This is why glue code and tools like wasm-bindgen exist — they automate this serialisation.
3 / 5
'Shared memory between WASM and JS.' What is the WASM linear memory?
WASM's linear memory is a flat, contiguous block of memory (a WebAssembly.Memory object backed by an ArrayBuffer). WASM code reads and writes this memory as its heap. JavaScript can access the same memory by creating a typed array view (e.g., new Uint8Array(memory.buffer)) and reading/writing directly. This shared memory model is how complex data (strings, arrays, structs) is passed between WASM and JS.
4 / 5
'The glue code handles type conversion.' What is WASM glue code?
Glue code is JavaScript that handles the complexity of the WASM-JS interface: allocating memory for strings, writing bytes into the WASM heap, calling the WASM function with a pointer and length, reading the result back, and freeing memory. Without glue code, every cross-boundary call would require writing this boilerplate manually. Tools like wasm-bindgen, Emscripten, and wasm-pack generate this automatically.
5 / 5
'wasm-bindgen automates Rust-to-JS bindings.' What does wasm-bindgen do?
wasm-bindgen is a Rust tool and crate that bridges Rust and JavaScript. Developers annotate Rust functions and types with #[wasm_bindgen], and the tool generates: the WASM binary with proper exports, JavaScript glue code that handles type conversion (Rust String ↔ JS string, Rust Vec ↔ JS Array), and TypeScript type definitions. This makes Rust-WASM feel idiomatic on both sides.