Skip to main content
InterviewHubPRO
Section Overview
Q32

Question 32 of 536

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

6%
JavaScript & V8 Internals (536 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What are modules

junior LevelMost AskedCode ExamplePrototypes

Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor

Practical Code Example

javascript
// mathUtils.js (ES Module definition)
export const add = (a, b) => a + b;
export const multiply = (a, b) => a * b;
export default function square(n) {
  return n * n;
}

// app.js (Importing module)
import square, { add, multiply } from './mathUtils.js';

console.log(add(3, 4));    // 7
console.log(square(5));    // 25