Why does Motoko compile to WebAssembly?

Motoko compiles to WebAssembly (Wasm) due to its versatility to operate across the internet. The Internet Computer leverages Wasm canisters to store data and execute code directly to the internet. Wasm is a binary instruction format for a stack-based virtual machine. It is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

The Wasm stack machine is designed to be encoded in a size- and load-time-efficient binary format. Wasm aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms. Wasm describes a memory-safe, sandboxed execution environment that may even be implemented inside existing JavaScript virtual machines. When embedded in the web, Wasm will enforce the same-origin and permissions security policies of the browser.

Wasm is designed to maintain the versionless, feature-tested, and backwards-compatible nature of the web. Wasm modules will be able to call into and out of the JavaScript context and access browser functionality through the same web APIs accessible from JavaScript. Wasm also supports non-web embeddings. Source: WebAssembly.org.

For these reasons as well as its compatibility across browsers, Motoko compiles down to Wasm. Additionally, any language that can compile down to Wasm can then be deployed on the Internet Computer.