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


Picture showing the output of the Default and named exports in JavaScript



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, August 26, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250