Default Exports

Let's learn the basics of default export and see its examples.

A default export may signify a major, the most significant, or the only export a module may like to expose. Although a module can have zero or more named exports, it can have at most one default export.

Where to use default exports?

Use a default export if you have only one reference or class to export. Even when you have multiple things to export, you may use a default export if most of your module’s users use a particular reference more frequently than other exported references.

How to use default exports?

To mark an export as default, follow the export keyword with the default keyword. Default exports have one restriction; however: export default is not permitted in front of the keywords const and let, while export without default is allowed.

In short, the inlining of default exports is permitted for functions and classes but not for variables and constants. You may explicitly export variables and constants as default.

Playing with default exports

Let’s export a function from our module as default.

Get hands-on with 1200+ tech skills courses.