100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
WebAssembly

WebAssembly Quick Reference

A condensed cheat sheet of WebAssembly core concepts, value types, module structure, and common toolchain commands for quick lookup.

PracticeBeginner8 min readJul 10, 2026
Analogies

Value Types and Module Structure

WebAssembly's core MVP defines four numeric value types: i32 and i64 for integers, and f32 and f64 for floating-point numbers, with a v128 SIMD type and reference types (funcref, externref) added by later proposals. A module is organized into sections in a fixed order in the binary format: type, import, function, table, memory, global, export, start, element, code, and data — each section is optional except that if present, they must appear in that order, which is why hand-editing a raw .wasm binary is error-prone compared to editing the WAT text representation and reassembling with a tool like wat2wasm.

🏏

Cricket analogy: Wasm's fixed section order is like the fixed structure of a Test match day: toss, then play, then lunch, then tea, then stumps — you can't reorder these phases even if a particular day's play is short.

wat
(module
  (import "env" "log" (func $log (param i32)))
  (memory (export "memory") 1)
  (global $counter (mut i32) (i32.const 0))

  (func (export "increment") (result i32)
    global.get $counter
    i32.const 1
    i32.add
    global.set $counter
    global.get $counter))

Common Toolchain Commands

A handful of commands cover most day-to-day Wasm development: wat2wasm and wasm2wat (from the WABT toolkit) convert between text and binary formats for debugging; wasm-opt from Binaryen optimizes a compiled module for size or speed with flags like -Oz for aggressive size reduction; wasmtime run executes a WASI module directly from the command line; and wasm-pack build handles the full Rust-to-browser pipeline in one step. For inspecting an unfamiliar .wasm file, wasm-objdump -x prints its section headers and import/export table, which is often the fastest way to understand what a third-party module expects and provides.

🏏

Cricket analogy: Having a standard toolkit of commands is like a fielding coach's standard drills: catching practice, throwing accuracy, and ground fielding, each addressing a specific skill without needing to invent a new drill every session.

bash
# Convert text format to binary and back
wat2wasm module.wat -o module.wasm
wasm2wat module.wasm -o module.wat

# Optimize for size (aggressive)
wasm-opt -Oz module.wasm -o module.min.wasm

# Inspect sections, imports, and exports
wasm-objdump -x module.wasm

# Run a WASI module directly
wasmtime run module.wasm

The Wasm MVP text format is officially called WAT (WebAssembly Text Format), and the binary format has the .wasm extension with magic bytes 0x00 0x61 0x73 0x6D ('\0asm') followed by a version number, which is the fastest way to confirm a file is genuinely a Wasm binary rather than something else.

wasm-opt's -Oz size optimization can sometimes strip debug information or reorder code in ways that make source-mapped debugging harder — keep an unoptimized build available for local debugging and only ship the -Oz output to production.

JavaScript API Quick Reference

The browser-facing JavaScript API centers on a handful of methods: WebAssembly.compile takes raw bytes and returns a compiled Module; WebAssembly.instantiate takes either bytes or a Module and returns an Instance with its exports ready to call; and WebAssembly.instantiateStreaming is the preferred method for loading directly from a network response since it can begin compiling while bytes are still downloading, rather than waiting for the full ArrayBuffer to arrive first. The imports object passed to instantiate must match exactly what the module's import section declares — mismatched signatures or missing import names throw a LinkError at instantiation time rather than failing silently.

🏏

Cricket analogy: instantiateStreaming compiling while bytes download is like a commentator analyzing a bowler's run-up before the ball is even released, processing available information as it streams in rather than waiting for the full delivery to complete.

  • Core value types: i32, i64, f32, f64, plus v128 (SIMD) and reference types (funcref, externref) from later proposals.
  • A Wasm module's binary sections have a fixed required order: type, import, function, table, memory, global, export, start, element, code, data.
  • WABT tools (wat2wasm, wasm2wat, wasm-objdump) convert and inspect modules; Binaryen's wasm-opt optimizes for size or speed.
  • wasmtime run executes WASI modules from the command line; wasm-pack build handles the full Rust-to-browser pipeline.
  • A valid .wasm binary starts with magic bytes 0x00 0x61 0x73 0x6D followed by a version number.
  • WebAssembly.instantiateStreaming is preferred over instantiate for network-loaded modules since it compiles while bytes download.
  • Mismatched or missing entries in the imports object passed to instantiate throw a LinkError rather than failing silently.

Practice what you learned

Was this page helpful?

Topics covered

#WebAssembly#WebAssemblyStudyNotes#WebDevelopment#WebAssemblyQuickReference#Quick#Reference#Value#Types#StudyNotes#SkillVeris