JavaScript Named Exports

swarnaliroy94

Swarnali Roy

Posted on July 31, 2021

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!
💖 💪 🙅 🚩
swarnaliroy94
Swarnali Roy

Posted on July 31, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Function Hoisting In JavaScript
javascript Function Hoisting In JavaScript

September 10, 2022

JavaScript getters and setters
javascript JavaScript getters and setters

May 9, 2022

JavaScript Basics in its Simplest Form
javascript JavaScript Basics in its Simplest Form

January 18, 2022

How to practice Javascript?
javascript How to practice Javascript?

October 12, 2021

The keyword "new" in JavaScript
javascript The keyword "new" in JavaScript

September 19, 2021