Open In App

ES6 Import and Export

The ES6 is a JavaScript standard. With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import. The export and import are the keywords used for exporting and importing one or more members in a module.

Export: You can export a variable using the export keyword in front of that variable declaration. You can also export a function and a class by doing the same.



Import: You can import a variable using import keyword. You can specify one of all the members that you want to import from a JavaScript file.

Note: The default member should be imported first and then the none default members in curly brackets.




Article Tags :