JavaScript import

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

import brings bindings from another module. Named imports must match export names (or use as). Default imports choose any local name.

JavaScript Syntax

JavaScript
// Conceptual: import { PI } from "./math.js";
const PI = 3.14; // stand-in for imported binding
console.log(PI);
Try it Editor

How It Works

  1. Live bindings. Named imports reflect exporter updates.
  2. Static. import runs at load time.

Examples

Example 1 — Default import

import Name from "./mod.js".

JavaScript
console.log("import App from './app.js'");
Try it Editor

How It Works

  1. Local name is your choice.

Example 2 — Namespace import

import * as mod from ...

JavaScript
console.log("import * as math from './math.js'");
Try it Editor

How It Works

  1. mod.PI style access.

Example 3 — Side-effect import

import "./init.js".

JavaScript
console.log("import './polyfill.js'");
Try it Editor

How It Works

  1. Runs module for effects only.

Frequently Asked Questions

Use <script type="module"> or a bundler. Classic scripts do not support ES import.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful