Skip to content
Tutorials Center
My learning

Topics

WebAssembly Tutorial

Learn WebAssembly step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is WebAssembly? Learn what WebAssembly (Wasm) is, why browsers and servers run it, how it differs from JavaScript, what it is good at, and where its limits are.
  2. 2 How WebAssembly Runs Follow a .wasm file from download to running code. Learn the decode, validate, compile and instantiate steps, the sandbox, hosts, and why validation matters.
  3. 3 Your First Wasm Module Build and run a real WebAssembly module from scratch. Learn the type, function, export and code sections, plus a tiny JavaScript byte builder used in this course.
  4. 4 The WebAssembly JavaScript API A tour of the WebAssembly JavaScript API. Use validate, compile, instantiate, Module, Instance and streaming loading in browsers and Node.js, with runnable examples.
  5. 5 Value Types and Numbers Understand the four number types of WebAssembly, signed versus unsigned integers, i64 and BigInt, float rounding, conversions, and the other value types.

Modules, Memory and Tables

  1. 6 Module Structure and Sections Learn every section of a WebAssembly binary module, their order, index spaces, the start function and custom sections, with a runnable section dumper.
  2. 7 Linear Memory Learn how WebAssembly linear memory works. Create a Memory in JavaScript, share it with a module, read and write bytes, grow it safely and handle out-of-bounds traps.
  3. 8 Data Segments and Strings Learn how WebAssembly stores strings and constant data. Use active and passive data segments, UTF-8 with TextEncoder and TextDecoder, and memory.init with data.drop.
  4. 9 Tables and Indirect Calls Learn how WebAssembly tables hold function references, how call_indirect implements function pointers and virtual methods, and how to manage tables from JavaScript.
  5. 10 WebAssembly Globals Learn WebAssembly global variables. Declare mutable and immutable globals, use global.get and global.set, and share them with JavaScript through WebAssembly.Global.

The Text Format

  1. 11 WebAssembly Text Format (WAT) Basics Learn the WebAssembly text format (WAT): S-expressions, modules, functions, flat and folded instructions, names, comments, and how to turn WAT into a .wasm file.
  2. 12 The Stack Machine and Instructions Learn how WebAssembly executes code on a stack machine. Trace instructions, use locals and local.tee, arithmetic, bitwise and comparison operators, select, and drop.
  3. 13 Control Flow in WebAssembly Learn structured control flow in WebAssembly text format: if/else, block, loop, br, br_if, br_table, return and unreachable, with factorial, gcd and prime examples.
  4. 14 Functions, Locals and Calls Learn WebAssembly functions: signatures, call, recursion, mutual recursion, multiple return values, early return, exports by name, and what happens on stack overflow.
  5. 15 Memory Instructions Learn the WebAssembly memory instructions: load and store variants, offset and alignment, memory.size, memory.grow, memory.fill and memory.copy, with array and string examples.

Calling Between JS and Wasm

  1. 16 Exporting Functions to JavaScript Learn how JavaScript calls WebAssembly exports: argument and result conversion for i32, i64, f32 and f64, multi-value, exported memories, tables and globals, and call overhead.
  2. 17 Importing JavaScript Functions Learn how WebAssembly modules import JavaScript functions: the import object, console.log and Math imports, callbacks, LinkError, re-entrancy and exceptions across the boundary.
  3. 18 Passing Strings and Arrays Learn the pointer and length pattern for strings and arrays in WebAssembly: a bump allocator, TextEncoder, typed array views, returning strings, and the stale-view pitfall.
  4. 19 Traps and Errors Learn every way WebAssembly can fail: CompileError, LinkError, RuntimeError traps, stack overflow, out of memory, and how to catch them. Includes the exception handling Tag and Exception API.

Compiling from C, Rust and Others

  1. 20 Compiling C to WebAssembly with Emscripten Learn how to compile C code to WebAssembly with Emscripten - emcc flags, exported functions, cwrap, malloc and memory, plus runnable examples of what the compiler produces.
  2. 21 Compiling Rust to WebAssembly with wasm-bindgen Learn the Rust to WebAssembly workflow - targets, wasm-pack, wasm-bindgen glue, structs and Result types across the boundary - with runnable stand-ins for generated code.
  3. 22 Other Languages for WebAssembly Compare the languages that compile to WebAssembly - AssemblyScript, Go and TinyGo, Zig, C# Blazor, Kotlin, Swift - with runnable BigInt and feature-detection examples.
  4. 23 Passing Strings and Structs Across the Boundary Learn how strings, arrays and structs cross the JavaScript and WebAssembly boundary - UTF-8 encoding, pointer and length pairs, allocation, alignment and endianness, with runnable code.

Performance and Debugging

  1. 24 WebAssembly Performance Learn when WebAssembly is faster than JavaScript, how to benchmark fairly, why boundary crossings and copies cost time, and how startup, streaming and tiering affect real pages.
  2. 25 Debugging WebAssembly Learn to debug WebAssembly - reading traps, the name section and stack traces, DWARF debug info and source maps in browser DevTools, logging from wasm, and a checklist for common bugs.
  3. 26 Binary Size and Optimization Learn how WebAssembly binaries are laid out, why LEB128 keeps them small, and how wasm-opt, stripping, LTO, twiggy and Brotli compression shrink modules for faster page loads.
  4. 27 SIMD and Threads in WebAssembly Learn WebAssembly SIMD (v128 vectors) and threads (shared memory, atomics, Web Workers) with runnable examples, plus cross-origin isolation, feature detection and when each one pays off.

WASI and Beyond the Browser

  1. 28 What is WASI? The WebAssembly System Interface Understand WASI, the WebAssembly System Interface - capabilities, preopened directories, fd_write, args and environment, preview1 vs preview2 - with runnable Node WASI and hand-written host examples.
  2. 29 Running WebAssembly Outside the Browser Learn how to run WebAssembly on servers and the command line - Wasmtime, Wasmer, WasmEdge, wazero, Node.js and Deno - with args, environment, preopens, exit codes and embedding examples.
  3. 30 The WebAssembly Component Model and WIT Learn the WebAssembly Component Model - WIT interfaces and worlds, the canonical ABI that lifts and lowers strings and records, composition, wasm-tools, jco and cargo-component - with runnable stand-ins.
  4. 31 WebAssembly on Servers and the Edge Learn why WebAssembly suits servers, serverless and edge platforms - fast cold starts, per-request isolation, plugins and proxies - with runnable instance-isolation and memory-limit examples.

Patterns and Tooling

  1. 32 The WebAssembly Toolchain Tour the WebAssembly toolchain - wat2wasm, wasm-objdump, wasm-opt, wasm-tools, twiggy, wasm-pack - then build a module byte by byte and write a mini section inspector in JavaScript.
  2. 33 Bundlers and Loading Strategies for WebAssembly Learn how to load WebAssembly in real apps - fetch and instantiateStreaming, MIME types, Vite and Webpack imports, lazy loading, caching, Web Workers and fallbacks - with runnable loader examples.
  3. 34 Plugin Systems with WebAssembly Learn to design a plugin system on WebAssembly - host API as the only imports, allow-lists, LinkError rejection, fuel limits against infinite loops, versioning, data passing and lifecycle - with runnable code.
  4. 35 The WebAssembly Security Model Understand WebAssembly security - sandboxed linear memory, bounds checks, validation, protected call stack, typed indirect calls, what the sandbox does not protect and host-boundary rules, with runnable demos.

Projects and Practice

  1. 36 Project: Image Filter in WebAssembly Build an image filter with WebAssembly - RGBA pixel memory, a grayscale and invert module, zero-copy typed-array views, a JavaScript reference, tests, benchmark and the Canvas wiring for the browser.
  2. 37 Project: Prime Sieve and a Benchmark Harness Build a prime sieve in WebAssembly, verify it against known prime counts, write a reusable benchmark harness with warm-up, median and spread, and learn to interpret the results honestly.
  3. 38 WebAssembly Practice and Interview Questions Practice WebAssembly with interview questions and answers, coding exercises with runnable solutions, trap-prediction drills, a debugging checklist and a self-assessment, covering memory, imports, WASI and performance.