MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
What are Modules?0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
10.1What are Modules?10.2import & export10.3Organizing Code with Modules
HomeTutorialsJavaScript for IntermediateWhat are Modules?
import & export

What are Modules?

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

As JavaScript applications expanded from simple interactive button scripts into massive, full-scale enterprise software systems, managing code across thousands of lines became impossible without modularization. JavaScript Modules provide encapsulation, scope isolation, and explicit dependency management.


1. The Historical Context: The Global Scope Crisis

In the early days of the web, every JavaScript file shared a single, global execution context:

1<!-- LEGACY: Everything polluted window! -->
2<script src="utils.js"></script>
3<script src="auth.js"></script>
4<script src="app.js"></script>

Critical Flaws of Global Scripts:

  1. 1
    Name Collisions: If utils.js defined const count = 0 and app.js declared const count = 5, the application would crash with collision errors.
  2. 2
    Order Dependency: If app.js loaded before utils.js, execution failed because dependencies were missing.
  3. 3
    Lack of Encapsulation: All internal variables and helper functions were exposed on window.

2. Evolution of Module Systems

1 1995: Global Scripts (window.myVar)
2 │
3 2009: CommonJS (Node.js: require / module.exports)
4 2010: AMD / RequireJS (Asynchronous Browser Loading)
5 │
6 2015: ECMAScript Modules (ESM) — The Universal Official Standard!
7 (import / export)
Module SystemSyntaxPrimary EnvironmentLoading Mechanism
ES Modules (ESM)import / exportModern Browsers, Modern Node.jsStatic Analysis, Asynchronous
CommonJS (CJS)require() / module.exportsLegacy Node.jsDynamic, Synchronous

3. Core Characteristics of ES Modules

  1. 1
    Strict Mode by Default: Every ES module automatically executes in 'use strict' mode.
  2. 2
    Module-Level Scope: Variables declared at top-level in a module are private to that module and never pollute the global window object.
  3. 3
    Single Execution (Singleton): A module is executed only once when first imported; subsequent imports receive the cached exports.
  4. 4
    Deferred Execution in HTML: <script type="module"> scripts are automatically deferred until the HTML document is fully parsed.
  5. 5
    CORS Protected: Modules loaded in browsers must comply with Cross-Origin Resource Sharing (CORS) rules.

4. Enabling Modules in the Browser

To load an ES module in HTML, set type="module":

1// main.js
2import { calculateTax } from './taxCalculator.js';
3 
4const tax = calculateTax(100);
5console.log('Tax:', tax);

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What happens to top-level variables declared inside an ES Module?
Question 2
What HTML attribute is required to tell the browser to treat a JavaScript file as an ES Module?
Question 3
Are ES modules executed in strict mode?
Question 4
How many times is a module executed if it is imported by 5 different files in the same app?
Question 5
What legacy module format was popularized by Node.js using require() and module.exports?
Next Lesson

import & export

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Error Handling in Async Codeimport & export

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext