ES6 EXPORTS
There are 2 types of exports: a. Named Exports b. Default Exports
You can have as many
named exports
as you want in a file/module. But you can only have _ONE_**default export
.**You can export any data structure you choose.
If you do not export a variable or function from the file it will not be accessible to other files/modules
Named Export Examples
export const str = 'Hello World';
export const num1 = 100;
export const num2 = 200;
export const array = ['apple', 'pear', 'banana'];
export const obj = {
firstName: 'Foo',
lastName: 'Bar'
};
export function add(number1, number2) {
return number1 + number2;
}
You Can Only Have One Default export per module/file
export default subtract(number1, number2){
return number1 - number2;
}
This also applies to components. If you have more than one component in the same file to export, you can only export default one of them
Go to Imports to see how to import
LINKS
Learning Objectives, (no answers)
Learning Objectives With Answers
Imports CheatSheet
Exports CheatSheet
Imports, Exports One-to-One
Last updated
Was this helpful?