0% found this document useful (0 votes)
34 views10 pages

Import Export Modules

1. A JavaScript module is a file that contains code and can export values to be used by other programs. 2. Modules use export statements to export values and import statements to import exported values from other modules. 3. There are default exports which can be imported with any name, and named exports which must be imported using the same name.

Uploaded by

dk1078451
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views10 pages

Import Export Modules

1. A JavaScript module is a file that contains code and can export values to be used by other programs. 2. Modules use export statements to export values and import statements to import exported values from other modules. 3. There are default exports which can be imported with any name, and named exports which must be imported using the same name.

Uploaded by

dk1078451
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

What is Module

In JavaScript, Module is a JavaScript file where we


write codes. The object in a module are not available for
use, unless the module file exports them.
Exporting Module
export - The export statement is used when creating JavaScript modules to
export functions, objects, or primitive values from the module so they can be
used by other programs with the import statement.
There are two different types of export - named and default. You can have
multiple named exports per module but only one default export.
Default Export
You can have only one default export per module. A default export can be
imported with any name.
mobile.js
export default class Nokia { export default function show() {
Properties
Methods } export default const a = 10;
}
class Nokia { function show() { const a = 10;
Properties } export default a;
Methods export default show;
}
export default Nokia;
Named Export
You can have multiple named exports per module. Named exports are useful to export several
values. During the import, it is mandatory to use the same name of the corresponding object.

mobile.js
export class Nokia { export function show () { export const a = 10;
Properties
Methods }
}

class Nokia { function show () { const a = 10;


Properties export {a};
Methods }
}
export {show};
export {Nokia};
Named Export
You can have multiple named exports per module. Named exports are useful to export several
values. During the import, it is mandatory to use the same name of the corresponding object.

mobile.js
class Nokia {
Properties
Methods
}
export {Nokia, show};
function show () {

}
export const a = 10;
Importing Module
import - The static import statement is used to import bindings which are
exported by another module. Imported modules are in strict mode whether you
declare them as such or not.
Importing Defaults
You can have only one default export per module. A default export can be
imported with any name.

mobile.js app.js
class Nokia { import Nokia from ‘./mobile.js’
Properties
Methods
}
export default Nokia;
Importing Named
You can have multiple named exports per module. Named exports are useful
to export several values. During the import, it is mandatory to use the same
name of the corresponding object.
mobile.js app.js
export class Nokia {
import {Nokia} from ‘./mobile.js’
Properties
Methods import {Nokia, show}from ‘./mobile.js’
}
function show () {

}
export {show};
Importing All
mobile.js app.js
class Nokia { import * as device from ‘./mobile.js’
Properties
Methods
} device.Nokia
export function show () { device.show
device.a
}
Export const a = 10;
export {Nokia};
Importing Default and Named
mobile.js app.js
class Nokia { import Nokia, {show} from ‘./mobile.js’
Properties
Methods
}
export function show () {

}
export default Nokia;

You might also like