Learn WAT with Real Code Examples
Updated Nov 25, 2025
Explain
WAT provides a low-level, readable, LISP-like syntax for WebAssembly modules.
It directly maps to the binary WebAssembly format, instruction-by-instruction.
Used primarily for debugging, hand-crafted Wasm, education, and minimal runtime experimentation.
Supports fine-grained control over Wasm memory, functions, imports, exports, and types.
Typically compiled into Wasm using wat2wasm tools or integrated toolchains.
Core Features
Module definitions using `(module ...)`
Functions with explicit param/returns
Linear memory definition and access
Imports and exports
Instructions for control flow, arithmetic, memory, tables
Basic Concepts Overview
Stack machine - operations push/pop values
Linear memory - explicit memory access
S-expressions - LISP-like syntax
Instructions - Wasm opcodes in text form
Module structure - imports, exports, functions, types
Project Structure
module.wat - main Wasm text module
module.wasm - compiled binary
index.js - loader/interop script
tests/ - validate Wasm output
examples/ - sample WAT modules
Building Workflow
Write .wat module
Compile using wat2wasm
Inspect binary via wasm2wat
Load in browser or Node.js
Call exported functions from JS
Difficulty Use Cases
Beginner: simple add function
Intermediate: memory access + loops
Advanced: tables, imports & exports
Expert: manual stack manipulation + complex control flow
Auditor: analyze binary from wasm2wat
Comparisons
WAT vs Wasm Binary: WAT is readable; binary is compact and executable
WAT vs Rust-Wasm: WAT is manual; Rust generates Wasm automatically
WAT vs AssemblyScript: WAT is low-level; AS is high-level TS-like
WAT vs C/C++-Wasm: WAT is hand-crafted; C compiles high-level code
WAT vs Go/TinyGo: WAT avoids runtimes entirely
Versioning Timeline
2015 - WebAssembly concept announced
2017 - WebAssembly MVP in browsers
2018 - WAT standardized as text format
2022 - WAT gains support for GC, reference types
2024–2025 - Memory64, tail calls, component model support
Glossary
WAT - WebAssembly Text Format
S-expression - LISP-like syntax
Stack machine - push/pop architecture
WASI - WebAssembly System Interface
Opcode - low-level instruction