🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #234

Modules Import

Import

You can import modules in two ways, based on if they are named exports or default exports.

import { name, age } from "./person.js";
import message from "./message.js";

Named Imports

Named imports match named exports in a module.

They let you import one or more explicitly named variables or functions from a module.

You must use the exact names enclosed in curly { } braces:

Examples

import { name, age } from "./person.js";

Named Import Rules

Import names must match export names:

import { addd } from './math.js'; // ❌ Error (name mismatch)

You can import multiple items at once:

import { add, PI } from './math.js';

You can rename them using as:

import { add as addition } from './math.js';

Default Import

Default import is the way to import the primary exported value from a module - the one that was exported using export default.

Defalt imports are the counterpart to default exports.

You can give a default export any name you like, during import, without using curly braces:

Examples

import text from "./message.js";

Default Import Rules

Default import imports single default exports

import message from "./message.js";

There is no required name. Renaming is allowed.

import text from "./message.js";

Default + Named Import

A module can provide one main function plus some helpers:

Module File

export default function parse() { ... }

export function validate() { ... }

export function format() { ... }

Importing All

You can import all named exports from a module as a single object using the * syntax.

Examples

// Import all named exports from person.js

import * as person from "./person.js";

Default Import vs Named

Col 1 Col 2 Col 3
Feature Default Import Named Import
Typical use case One main feature per module Multiple features
Matches export name? No (you choose) Yes (must match)
Can rename freely? Always Only with as
Export count Only one default export allowed Multiple exports allowed

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Modules Import – FAQs

Quick answers about learning Modules Import in JavaScript.

This free note from CodingNow 2.0 explains Modules Import in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including Modules Import, is 100% free with no signup required.
With focused practice, most students grasp Modules Import in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now