JavaScript Modules

By admin , 27 June, 2026

Do you know how what is JavaScript Modules. Don't worry we'll cover everything, just keep reading techbrushup

What are Modules?

Modules is a fundamental feature in modern JavaScript.

A module is a reusable piece of code latter you can import whereever you want to import.

Modules let you to break up code into separate files.

Required Steps to Make a File a Module

1: Add Export Statements

2: Use type="module" in HTML (Browser Only)

3. Use Full File Paths in Imports

Types of JavaScript Modules

1. ES Modules (ESM) - Modern Standard

2. CommonJS (CJS) - Used in Node.js

The execution process is:

  • browser-based JavaScript modules files must be stored on a server.
  • browser-based JavaScript modules only work with the HTTP(s) protocol.
  • browser-based JavaScript modules A web-page opened via the file:// protocol cannot use import / export.

javaScript modules always operate in strict mode by default, and you cannot opt out

What is Strict Mode?

1. Variables Must Be Declared

2. Can't Delete Variables, Functions, or Parameters

3. No Duplicate Parameter Names

4. No Using with Statement

5. Safer this Behavior

6. No Octal Numbers

7. Cannot Assign to Read-Only Properties

8. Reserved Words Cannot Be Used as Variable Names


Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.