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.
(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.
# 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.wasmThe 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
1. Which four value types make up WebAssembly's original MVP numeric type system?
2. What must be true about the order of sections in a WebAssembly binary module?
3. What is the primary advantage of WebAssembly.instantiateStreaming over WebAssembly.instantiate with a pre-fetched ArrayBuffer?
4. What error is thrown if the imports object passed to WebAssembly.instantiate doesn't match the module's declared imports?
5. What are the first four bytes ('magic number') of every valid .wasm binary file?
Was this page helpful?
You May Also Like
WebAssembly Ecosystem Overview
A tour of the languages, toolchains, runtimes, and platforms that make up the WebAssembly ecosystem in 2026, from browser sandboxes to server-side WASI workloads.
Comparing Wasm Runtimes
A practical comparison of Wasmtime, WasmEdge, wasmer, and browser engines, covering performance, WASI support, and ideal use cases for each.
Building a Simple Wasm App
A hands-on walkthrough of building, compiling, and running a small WebAssembly module in both the browser and a standalone WASI runtime.
Related Reading
Related Study Notes in Web Development
Browse all study notesWebSockets Study Notes
Web Development · 30 topics
Web DevelopmentgRPC Study Notes
Protocol Buffers · 30 topics
Web DevelopmentSpring Boot Study Notes
Java · 30 topics
Web DevelopmentFlask Study Notes
Python · 30 topics
Web DevelopmentDjango Study Notes
Python · 30 topics
Web DevelopmentNext.js Study Notes
JavaScript · 30 topics