Default export:
Default export is easy way to export a function to outside module.
//flash-message.js export default function(message){ alert(message); } //app.js import flashMessage from './flast-message'; flashMessage("Hello");
Default export can only export one function pre module:
//flash-message.js export default function(message){ alert(message); } // Not available outside this module function logMessage(message) { console.log(message); }
Using named exprots:
In order to export multiple functions from a single module, we can use naming exprots.
// flash-message.js function alertMessage(message) { alert(message); } function logMessage(message) { console.log(message); } export {alertMessage, logMessage}; //app.js import {alertMessage, logMessage} from './flash-message'; alertMessage("Hello"); logMessage("Hello");