Articles → JAVASCRIPT → Default And Named Exports In Javascript
Default And Named Exports In Javascript
Purpose
Example
{
"type": "module",
"scripts": {
"start": "ImportClass.js"
}
}
// Default Export
export default function ClickMe() {
console.log("ClickMe function");
}
// Named Export
function ClickMe2() {
console.log("ClickMe2 function");
}
function ClickMe3() {
console.log("ClickMe3 function");
}
export {
ClickMe2,
ClickMe3
}
import ClickMe from './ExportClass.js';
import {
ClickMe2,
ClickMe3
} from './ExportClass.js';
// Default Import
ClickMe();
// Named Import
ClickMe2();
ClickMe3();
Output