JavaScript Named Exports
Swarnali Roy
Posted on July 31, 2021
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;
}
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} ;
Two different methods, working the same way! Choose which one is best for you!
💖 💪 🙅 🚩
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.