Named & Default Exports

This lesson briefly explains the difference between Named and Default exports and how to make to both type of exports in JavaScript.

All the cases discussed in the previous lesson were named imports and exports. But there exists the default statement too. Adding a default keyword before any class definition makes it a default thing which we want to export from the given module. It can be used for a few use cases:

  • to export and import a single functionality from a module
  • to highlight the main functionality of the exported API of a module
  • to have a fallback import functionality

Syntax:

  • To make a class default export inside a module
export default class_name {....}
  • To import a default export class from a module
import class_name from module_name;

Get hands-on with 1400+ tech skills courses.