DEV Community

Discussion on: Explain WebAssembly Like I'm five

Collapse
 
ejbroeders profile image
EJBroeders

WebAssembly is a binary format for web applications. That is, it is the format for applications for the web, which is very similar to what Javascript is.

However, developers don't write WebAssembly by hand (which is possible with Javascript). Instead they write some C, C++, Rust, or any other language code, which is compiled into WebAssembly. Similar to how a desktop application is written in some language, and then compiled into a binary format/file often with a .exe extension on Windows.

The main advantage is that WebAssembly has some optimizations built in which are impossible to build into the Javascript runtime environment. One example is garbage collecting. The Javascript engine in your browser has to keep track of all objects and free the memory when such objects can no longer be referenced from within the script. Obvious it takes time for the Javascript engine to keep track of all objects, allocations, and references. However WebAssembly has no garbage collecting mechanism and relies fully on the developer to keep track of his memory allocations. Therefore a WebAssembly program can run faster than a Javascript application. The down side is that it is a bit more difficult to develop WebAssembly applications because of that.

On a side-note, that's why Rust is now a popular language to write WebAssembly applications in. Rust is a fairly new language backend by Mozilla which has some neat syntax rules to keep track of memory allocations.

So in summary, it is a binary format for web applications which allows web applications to behave more like desktop applications. The main advantage is performance, and the main down side is that development is a bit tougher.

Collapse
 
renannobile profile image
Renan Lourençoni Nobile

Thank you very much.

Collapse
 
ejbroeders profile image
EJBroeders

You're welcome :-)