For over two decades, JavaScript was the only programming language that could run in browsers. Other languages like Python, C++, and Go were mainly for building the server side of web applications and services.

JavaScript did pretty well, but many other programming languages are faster. There are many benefits that web apps can take advantage of by running other, more performant programming languages directly in the browser.

WebAssembly offers an efficient, open, and safe option that’s part of the open web platform. You can use it to build applications that run on browsers, servers, and in other environments.

Introducing WebAssembly

WebAssembly introduction

WebAssembly (WASM) is an efficient, low-level, portable W3C-standardized language. It defines a code format and interfaces for programs to interact with platforms on the web.

You can compile most programming languages into WebAssembly’s binary code format. Browsers can interpret and run the resulting WASM code just as they do with regular JavaScript. You can also run WebAssembly alongside JavaScript code for higher app performance and interoperability between the two.

WebAssembly became a W3C standard in 2019, with support in many programming languages. According to Made with WebAssembly, there are already many popular projects that use WebAssembly to ship fast, secure software to their users.

A lot of programming languages, including those that are server-side specific, support WebAssembly. These include Rust, Go, Python, C++, TypeScript, Java, PHP, and Ruby. Check out the awesome-wasm-langs resource to learn about the WebAssembly-supported languages and the packages you can use with them.

Here’s an example WebAssembly program from Tutorials Point that returns a maximum of two integers:

A WASM code sample

The WebAssembly syntax is relatively verbose compared to JavaScript, but that shouldn’t be a problem. You won’t need to learn the syntax since WebAssembly will be the compilation target for the programs you write in your preferred language.

How WebAssembly Works

WASM exists as a compilation target for other programming languages to transpile into. You can write in your favorite programming language and compile the source code to WASM bytecode that runs on the client. Translating it into native machine code means it can run at high speed, typically faster than JavaScript.

One of the critical features of WASM is JavaScript interoperability. You can import WASM modules into a web application and expose the WASM functions for use in JavaScript code. JavaScript frameworks can take advantage of WASM for higher performance.

WASM uses a sandboxed execution model similar to JavaScript. WASM interacts with the host machine using ABIs (Application Binary Interface) like the WebAssembly System Interface that provides access to resources and other system services based on the program’s requirements.

Many modern browsers support WASM, including Chrome, Microsoft Edge, Mozilla Firefox, Opera, and Safari. Languages like Go and Rust support WASM out of the box.

Why the Web Needs WebAssembly

WebAssembly features

JavaScript has limited functionality by design. It’s not one of the fastest or most performant languages since it started as a scripting language for the web. Although there are many runtimes where JavaScript runs at varying speeds, there are faster and more performant languages that WebAssembly can bring to the web for use cases like gaming, videos, and music.

WebAssembly also offers more portability and flexibility to languages that don’t run on the web. Introducing more languages to the web (the most popular open-source platform) should result in an improved experience overall.

WebAssembly Adoption Is Fast Paced

Many companies and developers are building applications with WebAssembly. Google, Dropbox, and Cloudflare actively use WebAssembly in some of their applications.

WebAssembly is popular among Python, C++, and Rust developers. Python developers commonly use Pyoidide and PyScript, C++ developers and Emscripten, and Rust developers with Percy, Yew, Sycamore, MoonZoon, and the Seed framework.