ekjcfn3902039
ekjcfn3902039

Reputation: 1839

javascript - export default types

I'm aware you can do the following:

const foo = (bar) => { //some code... };
const baz = () => { //some code... };
export default { foo, baz, ... }

or

export default {
  foo: (bar) => //some code,
  baz: () => //some code,
  ...
}

Is there an advantage of one over the other, or is it merely a preference style?

Upvotes: 0

Views: 46

Answers (2)

Kendall Adkins
Kendall Adkins

Reputation: 36

It is all preference. The first is a bit more readable, in my opinion. Declare your variables and then export the ones that you need. If you decide to split up your exports than the second wouldn't really work all too well.

Upvotes: 1

Taki
Taki

Reputation: 17654

in the first example you can access both functions , like

const foo = (bar) => { //some code... };
const baz = () => { foo(); //some code that uses foo() };
export default { foo, baz, ... }

in the second one , you can't.

Upvotes: 1

Related Questions