Posts > default exports vs named export

default exports vs named export

Why export in javascript?

  • cleaner code
  • one source of files to look into
  • utils folder is a good way to use exports

You can export function() , [array], {object}, class.

👌You can have named and default export in one source and import them together as well. import Data, {data2, data3} from ./exportFile.js

Default Export

const data = [
	{},
	{},
]

export default data;

There’s only one default export per module.

import data from './exportData.js'

Named Export

export const data = [
	{},
	{},
]

export const data2 = [
	{},
	{},
]

can be helpful to export multiple values from one source

import {data, data2} from './exportData.js'

Tags 🏷