Additional information on export

We need to use the export statement in a module to export variables. The export statement comes in many different formats. Here are the formats:

  • export {variableName} - This format exports a variable
  • export {variableName1, variableName2, variableName3} - This format is used to export multiple variables
  • export {variableName as myVariableName} - This format is used to export a variable with another name, that is, an alias
  • export {variableName1 as myVariableName1, variableName2 as myVariableName2} - This format is used to export multiple variables with different names
  • export {variableName as default} - This format uses default as the alias
  • export {variableName as default, variableName1 as myVariableName1, variableName2} ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.