What does export (named, default) mean in JavaScript?

When developing a module in JavaScript, the export statement is used to export live bindings to functions, objects, or primitive values from the module. These data can be used by other modules, app with the import statement.

Exported modules are in strict mode whether you declare them as such or not.

// Exporting individual features 
export let age = 20, name = 'Tester';

// Export list 
export { 10, 20.50, 'Templates', [0,1,2,3,4] }; 

//Exporting everything at once 
export { object, number, x, y, boolean, string } 

// Renaming exports 
export { variable1 as newName1, variable2 as newName2}; 

//export function
export function functionName(a){
	return a*10;
}

// export funcitons, vriables declared earlier 
export { function1, function2, variable1, variable2 }; 

There are two types of export, named and default. You can have multiple named exports per module but only one default export.

Named exports are useful to export several values while default exports are useful to export only a single object, function, variable.

export default functionname () { ... } 
export default className { .. }

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close