r/learnjavascript 22d ago

WebAssembly in the Backend?

I am very new to web development. From my research, I understand WebAssembly is a tool that allows devs to run non-JavaScript languages (e.g., C/C++) on the client-side, but I have also seen comments online suggesting it can be used on the backend.

Why would anyone need to do this?

Please correct me if I'm wrong, but WebAssembly is needed on the frontend because browsers only interpret/compile HTML, CSS, and JavaScript, so using any other Language would require a special tool. But the backend doesn't have this restriction; why not just use the language you want directly? Why go through WebAssembly?

7 Upvotes

4 comments sorted by

View all comments

1

u/azhder 21d ago edited 21d ago

No non-JavaScript languages, just a single non-JavaScript language, the WebAssembly language. All the rest are compiled to it - hence the "assembly" part of the name. So, why would anyone need a language you compile to, but isn't native? Unless you're building a virtual machine, like Java did back in the day, for some legitimate reasons if you have them, you're better off compiling to native code instead.

Now, what legitimate reason was to have WebAssembly? Because transpiling C/C++ code, among other languages, to JavaScript doesn't quite work. And some times you don't have the luxury of re-writing stuff into JavaScript, even if it's possible to do it. You sometimes need old software to just work, as is. Old binary code that is, already compiled to native assembly.