## 2 Understanding WebAssembly
### Interoperability of Wasm  
The portable nature of Wasm's binary format enables it to run across a variety of platforms and environments. This cross-platform compatibility is central to Wasm's design philosophy, allowing developers to write code once and run it anywhere, whether in a desktop browser, a mobile browser, a server environment, or an IoT device. Wasm provides a foreign function interface (FFI) for interoperation with other languages. This means that Wasm can be used to build web applications as well as to provide high-performance components for Python, Ruby, PHP, Java, and.NET applications, among others. Wasm's design supports interoperability, ensuring that it can function seamlessly alongside traditional web technologies such as JavaScript and can access various web APIs. This section further explores the various aspects of Wasm's interoperability. * **Interaction with JavaScript** Wasm is designed to complement and work side-by-side with JavaScript. Wasm modules can be loaded and executed from JavaScript, allowing developers to run complex computations using Wasm while leveraging JavaScript for less performance-sensitive tasks. This interaction between JavaScript and Wasm is facilitated by the Wasm JavaScript API, which includes functions to compile and instantiate Wasm modules. Furthermore, Wasm and JavaScript can share data using Wasm's linear memory, a contiguous and resizable array of bytes that JavaScript can read from and write to. This shared memory model allows for efficient communication between Wasm and JavaScript, enabling complex applications that utilize the strengths of both languages. * **FFI** The FFI is a mechanism through which a program written in one programming language can call routines or make use of services written in another [14; 15]. FFI is used when two languages do not share a common interface or when they cannot interact directly with each other. Wasm utilizes an FFI to enable interoperability with JavaScript and other programming languages. Through the FFI, Wasm can call functions written in JavaScript and vice versa. This is critical because it allows Wasm to leverage the extensive ecosystem of JavaScript libraries and the broader web platform. The FFI plays a significant role in Wasm's integration with other languages in non-web contexts as well. Languages such as Rust, Go, and C/C++ can compile to Wasm and interact with other systems or libraries through the FFI. This interaction is critical for many use cases, especially when it comes to system-level programming in fields such as IoT. However, working with the FFI can be quite complex due to the difference in memory models between Wasm and other languages. Wasm's linear memory model is different from the models used by most programming languages, and translating between the two can be challenging. Solutions such as the Wasm Interface Typesproposal are aimed at making this easier, and interoperation between Wasm and other languages is expected to become more seamless as these improvements are adopted. * **Access to Web APIs** Wasm can indirectly access various web APIs through JavaScript. While Wasm cannot directly call web APIs, it can call JavaScript functions that can interact with these APIs. This model provides a layer of abstraction that enhances security while enabling the rich functionality that web APIs offer. In the future, with the integration of the Wasm Interface Types proposal, Wasm modules will be able to directly interact with web APIs, enhancing its interoperability and functionality. * **Compatibility Across Browsers** Wasm modules are designed to be portable, meaning that they can run on any platform that provides a compliant Wasm virtual machine. This includes all modern web browsers (Google Chrome, Mozilla Firefox, Safari, and Edge). This cross-browser compatibility ensures that a Wasm module developed on one platform can run seamlessly on another, enhancing the reach and usability of web applications built with Wasm.