Sample questions
Question 1Easy
What is WebAssembly (Wasm)?
- A binary format browsers run at near-native speed
- A CSS preprocessor that compiles to plain stylesheets
- A protocol for streaming video between browsers
- A JavaScript framework for building single-page apps
Answer: A. A binary format browsers run at near-native speed
Explanation
Wasm is a low-level binary instruction format designed as a compilation target for languages like C, C++ and Rust.
Step-by-step solution
- WebAssembly is a compact binary instruction format.
- Browsers run it at near-native speed.
- It is a compile target for C, C++, Rust and others.
Why the other options are wrong
- B. That describes Sass or Less.
- C. It is not a streaming protocol.
- D. It is not a JS framework.
Tip: Wasm = binary code for the web.
Question 2Easy
Which task is a typical good fit for WebAssembly in a web app?
- Rendering a static blog post
- Submitting a simple HTML form
- Toggling a CSS class when a button is clicked
- Image or video processing in the browser
Answer: D. Image or video processing in the browser
Explanation
CPU-heavy, algorithmic work (codecs, image filters, games, CAD) benefits most; simple DOM tasks gain nothing.
Step-by-step solution
- Wasm helps most with CPU-heavy, algorithmic work.
- Image and video processing is that kind of work.
- Simple DOM tasks and static pages gain nothing from Wasm.
- So the correct answer is image or video processing in the browser.
Why the other options are wrong
- A. A static blog post is simple rendering and gains nothing from Wasm.
- B. Submitting a simple form is a simple network and DOM task.
- C. Toggling a CSS class is a simple DOM task.
Tip: Use Wasm for heavy computation; keep DOM work in JavaScript.
Question 3Easy
Which JavaScript object provides the APIs for loading and running Wasm modules in the browser?
- Worker.asm
- window.wasm
- navigator.native
- WebAssembly
Answer: D. WebAssembly
Explanation
The global WebAssembly namespace has compile, instantiate, Memory, Module and related APIs.
Step-by-step solution
- The browser exposes Wasm through a global JavaScript namespace.
- That namespace provides compile, instantiate, Module and Memory.
- The name of that namespace is WebAssembly.
- So the correct answer is WebAssembly.
Why the other options are wrong
- A. Worker.asm is not a Wasm API.
- B. window.wasm is not a standard API.
- C. navigator.native is not a Wasm API.
Tip: Use the global WebAssembly object to compile and instantiate modules.
Question 4Easy
Is WebAssembly meant to replace JavaScript in the browser?
- No, Wasm only runs on servers, never in browsers
- No, it works alongside JS for heavy parts
- Yes, browsers are removing JavaScript support
- Yes, Wasm can directly replace the DOM API
Answer: B. No, it works alongside JS for heavy parts
Explanation
Wasm complements JS: JS handles the DOM and glue code, Wasm runs compute-heavy modules.
Step-by-step solution
- WebAssembly runs in browsers next to JavaScript.
- JavaScript still handles the DOM, events and glue code.
- Wasm is used for compute-heavy modules such as codecs or games.
- So the correct answer is that Wasm works alongside JS for heavy parts.
Why the other options are wrong
- A. Wasm runs in browsers; that is its main use.
- C. Browsers are not removing JavaScript support.
- D. Wasm cannot replace the DOM API; it calls JS to use the DOM.
Tip: Wasm complements JavaScript; it does not replace it.
Question 5Medium
What does WebAssembly.instantiateStreaming() improve over fetching then instantiating?
- It compiles while downloading
- It caches the module in localStorage
- It skips validation of the binary
- It converts the module to JavaScript
Answer: A. It compiles while downloading
Explanation
Streaming compilation overlaps download and compile, reducing startup time (it needs the application/wasm MIME type).
Step-by-step solution
- InstantiateStreaming takes the response stream directly.
- It starts compiling the module while the bytes are still downloading.
- This overlaps download and compile to cut startup time.
- So the correct answer is that it compiles while downloading.
Why the other options are wrong
- B. It does not cache the module in localStorage.
- C. Validation still happens; it is not skipped.
- D. The module stays Wasm; it is not converted to JavaScript.
Tip: InstantiateStreaming overlaps download and compile; the server must send application/wasm.
Question 6Medium
How does a WebAssembly module typically expose functions to JavaScript?
- By emitting DOM events with the results
- Through instance.exports
- By writing them into localStorage
- By attaching them to window automatically
Answer: B. Through instance.exports
Explanation
After instantiation, exported functions are callable like normal JS functions, e.g. instance.exports.add(2, 3).
Step-by-step solution
- A Wasm module is compiled and then instantiated in JavaScript.
- Its exported functions appear on the instance.
- They are read from instance.exports.
- So the correct answer is instance.exports.
Why the other options are wrong
- A. Results are returned from calls, not sent as DOM events.
- C. LocalStorage is not a function channel.
- D. Exports are not attached to window automatically.
Tip: After instantiation, call Wasm functions through instance.exports.
Question 7Medium
Which statement about WebAssembly security is correct?
- It bypasses CORS when fetching resources
- It runs outside the browser sandbox for speed
- It can read any file on the user's disk
- It runs in the same sandbox as the page JS
Answer: D. It runs in the same sandbox as the page JS
Explanation
Wasm executes inside the browser's sandbox with the same permissions as the page's JavaScript.
Step-by-step solution
- Wasm runs inside the browser sandbox.
- It has the same permissions as the page's JavaScript.
- It cannot read the user's files or skip CORS by itself.
- So the correct answer is that it runs in the same sandbox as the page JS.
Why the other options are wrong
- A. Wasm follows the same CORS rules as JavaScript.
- B. Wasm does not run outside the browser sandbox.
- C. Wasm cannot read arbitrary files on the user's disk.
Tip: Wasm security is the same as JavaScript security in the browser.
Question 8Medium
- A JavaScript bundler for Wasm modules
- A system interface for Wasm outside browsers
- A text format for writing Wasm by hand
- A browser API for Wasm DOM access
Answer: B. A system interface for Wasm outside browsers
Explanation
The WebAssembly System Interface gives Wasm portable access to things like files and clocks in runtimes outside the browser.
Step-by-step solution
- WASI stands for WebAssembly System Interface.
- It gives Wasm a portable way to use files, clocks and similar system features.
- It is used in runtimes outside the browser.
- So the correct answer is a system interface for Wasm outside browsers.
Why the other options are wrong
- A. WASI is not a bundler.
- C. The text format is WAT, not WASI.
- D. WASI is not a browser DOM API.
Tip: WASI = system calls for Wasm outside the browser.
Question 9Hard
Why is calling between JS and Wasm thousands of times per frame with small strings often slow?
- Every call triggers a network request
- Each call recompiles the whole Wasm module
- Wasm functions cannot return numbers to JS
- Strings must be encoded and copied each call
Answer: D. Strings must be encoded and copied each call
Explanation
Wasm only understands numbers and memory; strings must be encoded into linear memory and decoded back, so chatty calls cost more than batched work.
Step-by-step solution
- Wasm only works with numbers and linear memory.
- A string must be encoded and written into memory for each call.
- The result must then be decoded again.
- So the correct answer is that strings must be encoded and copied on each call.
Why the other options are wrong
- A. JS and Wasm calls do not use the network.
- B. Calls do not recompile the module.
- C. Wasm functions can return numbers to JS.
Tip: Batch work into fewer calls and avoid passing many small strings across the boundary.
Question 10Hard
The first four bytes of every WebAssembly binary are 0x00 0x61 0x73 0x6D. What do they spell?
- "java", the source language
- "wasm", the file extension
- "\0asm", the magic number
- "elf\0", the Linux header
Answer: C. "\0asm", the magic number
Explanation
0x61 0x73 0x6D are ASCII a, s, m; the header is the null byte followed by "asm", then a version field.
Step-by-step solution
- The bytes 0x00 0x61 0x73 0x6D are the start of every Wasm binary.
- 0x61, 0x73 and 0x6D are the ASCII letters a, s and m.
- With the null byte first, they spell the NUL character followed by asm.
- So the correct answer is the magic number \0asm.
Why the other options are wrong
- A. The bytes do not spell java, and the source language is not stored here.
- B. There is no wasm extension in the header bytes.
- D. Elf is the Linux binary header, which these bytes do not match.
Tip: A Wasm file starts with the magic number \0asm.
Practise all 14 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →