DEV Community

Swarnali Roy
Swarnali Roy

Posted on β€’ Edited on

2

JavaScript Named Exports

A very basic concept in JavaScript ES6 is Named Exports. This is a post with examples of two very simple approaches to export several values from a single module. It can be used zero or multiple times per module.

Named Exports

When we name export a variable or function, we can import it in another file and use it without having to rewrite the code.
We can export multiple things, for each thing we want to export.
The first example is given below:

export const addition = (a,b) => {
  return a+b;
}

export const multiplication = (a,b) => {
  return a*b;
}
Enter fullscreen mode Exit fullscreen mode

Another approach for named export is by creating multiple functions in one single module and placing them all in the export statement. The following is an example of that:

const addition = (a,b) => {
  return a+b;
}

const multiplication = (a,b) => {
  return a*b;
}

export {addition,multiplication} ;
Enter fullscreen mode Exit fullscreen mode
Two different methods, working the same way! Choose which one is best for you!

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (2)

Collapse
 
chetan_atrawalkar profile image
Chetan Atrawalkar β€’

Nice oneπŸ‘

Collapse
 
swarnaliroy94 profile image
Swarnali Roy β€’

Thanks

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay