WebAssembly Questions with Answers

14 practice questions on WebAssembly (Modern Web (Next.js, PWA, Performance)) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

What is WebAssembly (Wasm)?

  1. A binary format browsers run at near-native speed
  2. A CSS preprocessor that compiles to plain stylesheets
  3. A protocol for streaming video between browsers
  4. 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

  1. WebAssembly is a compact binary instruction format.
  2. Browsers run it at near-native speed.
  3. 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?

  1. Rendering a static blog post
  2. Submitting a simple HTML form
  3. Toggling a CSS class when a button is clicked
  4. 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

  1. Wasm helps most with CPU-heavy, algorithmic work.
  2. Image and video processing is that kind of work.
  3. Simple DOM tasks and static pages gain nothing from Wasm.
  4. 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?

  1. Worker.asm
  2. window.wasm
  3. navigator.native
  4. WebAssembly

Answer: D. WebAssembly

Explanation

The global WebAssembly namespace has compile, instantiate, Memory, Module and related APIs.

Step-by-step solution

  1. The browser exposes Wasm through a global JavaScript namespace.
  2. That namespace provides compile, instantiate, Module and Memory.
  3. The name of that namespace is WebAssembly.
  4. 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?

  1. No, Wasm only runs on servers, never in browsers
  2. No, it works alongside JS for heavy parts
  3. Yes, browsers are removing JavaScript support
  4. 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

  1. WebAssembly runs in browsers next to JavaScript.
  2. JavaScript still handles the DOM, events and glue code.
  3. Wasm is used for compute-heavy modules such as codecs or games.
  4. 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?

  1. It compiles while downloading
  2. It caches the module in localStorage
  3. It skips validation of the binary
  4. 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

  1. InstantiateStreaming takes the response stream directly.
  2. It starts compiling the module while the bytes are still downloading.
  3. This overlaps download and compile to cut startup time.
  4. 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?

  1. By emitting DOM events with the results
  2. Through instance.exports
  3. By writing them into localStorage
  4. 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

  1. A Wasm module is compiled and then instantiated in JavaScript.
  2. Its exported functions appear on the instance.
  3. They are read from instance.exports.
  4. 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?

  1. It bypasses CORS when fetching resources
  2. It runs outside the browser sandbox for speed
  3. It can read any file on the user's disk
  4. 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

  1. Wasm runs inside the browser sandbox.
  2. It has the same permissions as the page's JavaScript.
  3. It cannot read the user's files or skip CORS by itself.
  4. 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

What is WASI?

  1. A JavaScript bundler for Wasm modules
  2. A system interface for Wasm outside browsers
  3. A text format for writing Wasm by hand
  4. 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

  1. WASI stands for WebAssembly System Interface.
  2. It gives Wasm a portable way to use files, clocks and similar system features.
  3. It is used in runtimes outside the browser.
  4. 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?

  1. Every call triggers a network request
  2. Each call recompiles the whole Wasm module
  3. Wasm functions cannot return numbers to JS
  4. 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

  1. Wasm only works with numbers and linear memory.
  2. A string must be encoded and written into memory for each call.
  3. The result must then be decoded again.
  4. 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?

  1. "java", the source language
  2. "wasm", the file extension
  3. "\0asm", the magic number
  4. "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

  1. The bytes 0x00 0x61 0x73 0x6D are the start of every Wasm binary.
  2. 0x61, 0x73 and 0x6D are the ASCII letters a, s and m.
  3. With the null byte first, they spell the NUL character followed by asm.
  4. 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 →

Related topics

See all Modern Web (Next.js, PWA, Performance) topics · All topics