DEV Community

Swarnali Roy
Swarnali Roy

Posted on • Updated on

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!

Top comments (2)

Collapse
 
chetan_atrawalkar profile image
Chetan Atrawalkar

Nice oneπŸ‘

Collapse
 
swarnaliroy94 profile image
Swarnali Roy

Thanks