Calling JavaScript Functions from C/C++
Bridge the gap the other way: invoke JavaScript from your compiled C/C++ WASM code using Emscripten's interop tools.
Two-Way Interop
So far you have called C/C++ from JavaScript. But WASM code often needs to reach back into JS, to log, manipulate the DOM, or call browser APIs.
Emscripten provides several ways for your C/C++ code to call JavaScript.
Why Call JS at All?
WASM is sandboxed, it cannot touch the DOM, fetch, or timers directly. Anything outside pure computation must go through JavaScript.
- Update the page
- Read user input
- Use Web APIs like localStorage
All lessons in this course
- Compiling C/C++ to WASM with Emscripten
- Loading & Running WASM in JavaScript
- Basic Data Exchange: Primitives
- Calling JavaScript Functions from C/C++