Description #
WebAssembly (Wasm) is a low-level, binary instruction format designed to run at near-native speed in web browsers. It allows developers to compile code written in languages like C, C++, and Rust into a format that can be executed safely and efficiently on the web.
History #
WebAssembly was announced in 2015 as a joint effort by major browser vendors including Mozilla, Google, Microsoft, and Apple. Its goal was to provide a secure, portable, and high-performance alternative to JavaScript for computation-heavy applications. Wasm became an official web standard in 2019, and is now supported by all major browsers.
Key milestones:
- 2015: Project announced by W3C
- 2017: MVP (Minimum Viable Product) shipped in major browsers
- 2019: Became a W3C recommendation (official standard)
- Continues to evolve with support for threads, garbage collection, and more
Hello World Code #
watCopyEdit(module
(func $hello (export "hello")
(nop)
)
)
Or in a higher-level language like C (compiled to Wasm):
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
How to Run #
Using WebAssembly Studio:
- Visit https://webassembly.studio
- Choose a template (e.g., C → Wasm)
- Edit code and click “Build and Run”
Using command-line tools (for C/C++):
- Install Emscripten
- Compile:
emcc hello.c -o hello.html
Key Concepts #
.wasm
is the binary format;.wat
is the human-readable format- Sandboxed execution for security
- Language-agnostic (supports C, Rust, Go, etc.)
- Interacts with JavaScript via the WebAssembly API
- Compiled ahead-of-time for performance
- Ideal for games, image processing, and simulations
- Can be used outside browsers via WASI (WebAssembly System Interface)
- Faster startup and predictable performance
- Safe memory model (linear memory)
- Supported in all major browsers
Try It Online #
Fun Facts #
- WebAssembly is designed to complement, not replace, JavaScript
- It runs at near-native speeds in the browser
- You can compile entire game engines like Unity to Wasm
- Wasm binaries are usually smaller and faster than JavaScript
- The
.wasm
file format is platform-independent and runs safely in any environment that supports it