Export Keyword In JAVA SCRIPT (role and use)

Export Keyword use and role

image by DIX TECH : what is use and role of export and import keyword


if you are beginner in js then you are here don't worry it is very easy to you after time

export keyword here basic means of this keyword just to ensure what is it if you want to learn deep then click here

Use Of export Keyword

This is the code which written in an Module.js file
file name : module.js
//code starts
export const add = (x, y) => {
return x + y;
}
//code ends

Now index.js is the file where we want to add two numbers x and y

This is a new file name index.js and here randomly we want to use that add function which we have previuosly defined in module.js file

to use that function we have to use import keyword is work to import the add funtion from the given file

file name:index.js
// code starts
import add from ./module.js;

// now we can use the add() function in index.js wheather it is written in module.js named file

console.log(add(5,10)); // output definately print 15 without any error
//code ends

Now you will think about the question i.e; Why we not used the funtion
OR
it is same as function keyword when we use function const add = (x,y)=> { return x+y;}
add(5,10); // will return 15
Ans. So dude your question is write if you find the answer then comment us below and if you are looking for answer then

export default

Here yu will learn another form of export but with default keyword
like : export default

you will use this syntax if only one value is being exported from a file. It is also used to create a fallback value for a file or module.

You can have multiple named exports per module but only one default export

if you want to learn more about export keyword --> Click here

Comments

Pageviews