Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
The export keyword expects a list of methods to export contained within { }
.
It's essentially saying "export everything I specify".
You can export each method like so:
const _msg = "Hello World";
export const HelloWorld1 = () => { console.log(`${_msg} 1`); };
// or
// export function HelloWorld1()
// {
// console.log(`${_msg} 1`);
// };
Or you can do it at the end of the file like so:
const _msg = "Hello World";
const HelloWorld1 = () => { console.log(`${_msg} 1`); };
const HelloWorld2 = () => { console.log(`${_msg} 2`); };
export { HelloWorld1, HelloWorld2 };
You can even use aliases:
export { HelloWorld1, HelloWorld2, HelloWorld3 as HW3};
It's very important to remember that when you import any exported module(s), you use the type="module"
attribute.
<script src="javascripts/MyFile.js" type="module"></script>