Question Bank

JavaScript Modules and Encapsulation Quiz

Difficulty: Medium

Compare the module patterns that ship in modern JavaScript: ES modules, the revealing-module IIFE, classic singletons, and method-borrowing via `call`, `apply`, and `bind`.

Question Bank
/

JavaScript Modules and Encapsulation Quiz

JavaScript Modules and Encapsulation Quiz

Compare the module patterns that ship in modern JavaScript: ES modules, the revealing-module IIFE, classic singletons, and method-borrowing via `call`, `apply`, and `bind`.

Question Bank
Medium
JavaScript
5 questions
quiz
modules
js-es-modules
js-iife

1,187 views

15

Implement a small ES module mathUtils.js that exports two pure functions, add and subtract. Show how to consume them with named imports.

Examples

Example 1:

Input: import { add } from './mathUtils.js'; add(2, 3)
Output: 5
Explanation: Named exports surface the functions on the module record; the importer pulls them in by name.