
Modern JS: import and export
This article was originally published on bmf-tech.com . ※This article is a reprint from the Innovator Japan Engineers’ Blog . What is export export is a statement that allows you to receive functions, variables, objects, classes (classes are syntactic sugar for prototype-based inheritance and are a type of function. For more details, see Modern JS: Classes ), etc., from a specified file and use them in any file. There are mainly two ways to use export. Named exports This method involves naming the elements you want to export . export { fooFunction }; export { fooFunction , barFunction , ... }; export const foo = ' bar ' ; export let foo , bar , ...; export class foo {...}; You can export elements like this. You can also use var and let for exporting variables. Default exports This method uses the default keyword to export when you want to set a default element to export. export default fooFunction () {} export default class {} Note that var , let , and const cannot be used with export
Continue reading on Dev.to
Opens in a new tab


