The export default {...} construction is just a shortcut for something like this:

const funcs = {
    foo() { console.log('foo') }, 
    bar() { console.log('bar') },
    baz() { foo(); bar() }
}

export default funcs

It must become obvious now that there are no foo, bar or baz functions in the module's scope. But there is an object named funcs (though in reality it has no name) that contains these functions as its properties and which will become the module's default export.

So, to fix your code, re-write it without using the shortcut and refer to foo and bar as properties of funcs:

const funcs = {
    foo() { console.log('foo') }, 
    bar() { console.log('bar') },
    baz() { funcs.foo(); funcs.bar() } // here is the fix
}

export default funcs

Another option is to use this keyword to refer to funcs object without having to declare it explicitly, as @pawel has pointed out.

Yet another option (and the one which I generally prefer) is to declare these functions in the module scope. This allows to refer to them directly:

function foo() { console.log('foo') }
function bar() { console.log('bar') }
function baz() { foo(); bar() }

export default {foo, bar, baz}

And if you want the convenience of default export and ability to import items individually, you can also export all functions individually:

// util.js

export function foo() { console.log('foo') }
export function bar() { console.log('bar') }
export function baz() { foo(); bar() }

export default {foo, bar, baz}

// a.js, using default export

import util from './util'
util.foo()

// b.js, using named exports

import {bar} from './util'
bar()

Or, as @loganfsmyth suggested, you can do without default export and just use import * as util from './util' to get all named exports in one object.

Answer from skozin on Stack Overflow
Top answer
1 of 4
227

The export default {...} construction is just a shortcut for something like this:

const funcs = {
    foo() { console.log('foo') }, 
    bar() { console.log('bar') },
    baz() { foo(); bar() }
}

export default funcs

It must become obvious now that there are no foo, bar or baz functions in the module's scope. But there is an object named funcs (though in reality it has no name) that contains these functions as its properties and which will become the module's default export.

So, to fix your code, re-write it without using the shortcut and refer to foo and bar as properties of funcs:

const funcs = {
    foo() { console.log('foo') }, 
    bar() { console.log('bar') },
    baz() { funcs.foo(); funcs.bar() } // here is the fix
}

export default funcs

Another option is to use this keyword to refer to funcs object without having to declare it explicitly, as @pawel has pointed out.

Yet another option (and the one which I generally prefer) is to declare these functions in the module scope. This allows to refer to them directly:

function foo() { console.log('foo') }
function bar() { console.log('bar') }
function baz() { foo(); bar() }

export default {foo, bar, baz}

And if you want the convenience of default export and ability to import items individually, you can also export all functions individually:

// util.js

export function foo() { console.log('foo') }
export function bar() { console.log('bar') }
export function baz() { foo(); bar() }

export default {foo, bar, baz}

// a.js, using default export

import util from './util'
util.foo()

// b.js, using named exports

import {bar} from './util'
bar()

Or, as @loganfsmyth suggested, you can do without default export and just use import * as util from './util' to get all named exports in one object.

2 of 4
31

One alternative is to change up your module. Generally if you are exporting an object with a bunch of functions on it, it's easier to export a bunch of named functions, e.g.

export function foo() { console.log('foo') }, 
export function bar() { console.log('bar') },
export function baz() { foo(); bar() }

In this case you are export all of the functions with names, so you could do

import * as fns from './foo';

to get an object with properties for each function instead of the import you'd use for your first example:

import fns from './foo';
Discussions

javascript - ES6 export default function - Stack Overflow
can I export more than one function per file ? it seems like when I do that , the second function ovverides the first one , example : in my index.js file : export default function aFnt(){ c... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - ES6 how to do multiple default exports - Stack Overflow
I am still getting a hang of react+redux, and ES6. I am trying to implement socketio, and I come across the problem of having to export socketio connect with my redux's connect. redux connect exp... More on stackoverflow.com
🌐 stackoverflow.com
June 30, 2017
javascript - Nodejs - how group and export multiple functions in a separate file? - Stack Overflow
MDN Exports and the a short story about the state of javascript modules ... Sign up to request clarification or add additional context in comments. ... thanks for the answer. how is es5 exports like? what is considered es6 exports 2017-08-20T10:32:30.667Z+00:00 ... ES5 export is the old syntax like module.defaults ... More on stackoverflow.com
🌐 stackoverflow.com
A ES6 module with with multiple exports including a default export
error TS2309: An export assignment cannot be used in a module with other exported elements. An another question, if app.ts do a namespaced import will I have access to the default function too? More on github.com
🌐 github.com
4
March 20, 2015
🌐
Atomizedobjects
atomizedobjects.com › blog › javascript › how-to-export-multiple-functions-in-javascript
How to export multiple functions in JavaScript | Atomized Objects
August 27, 2021 - To export multiple functions in JavaScript, the easiest way to do so is by using the export statement before each function you want to export. As long as you do not export functions as default then you can export as many functions as you like from a module. All you have to do is apply the statement ...
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › multiple named exports in one javascript file
Multiple Named Exports in One JavaScript File | John Kavanagh
August 16, 2022 - You can export one default class per file with the ES6 modular syntax. A lot of codebases out in the wild don't use default exports, preferring to rely on more explicit export and import statements as it makes your development clearer (as well ...
🌐
Softwareshorts
softwareshorts.com › how-to-export-multiple-functions-in-javascript
How to export multiple functions in JavaScript | SoftwareShorts
And lastly, if you cannot use ES6 then you can use module.exports like so: 1const add = (a, b) => a + b; 2const multiply = (a, b) => a * b; 3const divide = (a, b) => a / b; 4 5module.exports = { add, multiply, divide }; In summary, there are many ways to export multiple functions in JavaScript but all of them will make use of the export statement or module.exports.
Find elsewhere
🌐
CoreUI
coreui.io › answers › how-to-export-a-function-in-javascript
How to export a function in JavaScript · CoreUI
November 19, 2025 - This pattern provides clean module boundaries and explicit dependency management. Use the export keyword before function declarations for named exports or export default for single function exports. // Named exports - multiple functions per ...
🌐
Bobby Hadz
bobbyhadz.com › blog › react-export-multiple-functions
Export multiple Functions or Components from file in React | bobbyhadz
April 7, 2024 - The import/export syntax is called ES6 Modules in JavaScript. In order to be able to import a function from a different file, it has to be exported using a named or default export.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › modules
Export and Import
In some situations the default keyword is used to reference the default export. For example, to export a function separately from its definition:
🌐
Codingem
codingem.com › home › how to export multiple functions in javascript
How to Export Multiple Functions in JavaScript - codingem.com
July 10, 2025 - To export multiple functions in JavaScript, call export by comma-separating the functions in curly braces. For example export { f1, f2, f3 }
🌐
Medium
medium.com › @ibeanuhillary › default-export-vs-named-export-which-is-better-51faa54a5937
Default Export vs. Named Export: Which is Better? | by Hillary Ibeanu | Medium
May 28, 2024 - Multiple Exports: The module needs to export multiple functions, objects, or values. Clarity: You want to make the module’s exports explicit and clear. Tooling: You want to leverage better IDE support for auto-completion, refactoring, and ...
🌐
DhiWise
dhiwise.com › post › the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
October 22, 2024 - Before diving into the specifics ... default and named exports. A default export can be imported without curly braces and is typically used for the main functionality of the js file....
🌐
Exploring JS
exploringjs.com › es6 › ch_modules.html
16. Modules
The second default export style was introduced because variable declarations can’t be meaningfully turned into default exports if they declare multiple variables: export default const foo = 1, bar = 2, baz = 3; // not legal JavaScript! Which one of the three variables foo, bar and baz would ...
🌐
GitHub
github.com › microsoft › TypeScript › issues › 2440
A ES6 module with with multiple exports including a default export · Issue #2440 · microsoft/TypeScript
March 20, 2015 - export default function function1() { console.log('hej') } export function function2() { console.log('hej') }
Author   tinganho
🌐
GeeksforGeeks
geeksforgeeks.org › what-is-export-default-in-javascript
What is export default in JavaScript ? | GeeksforGeeks
January 10, 2025 - There are two main types: default exports and named exports.Used to export functions, objects, or variables.Default exports allow importing with any name.Named exports require importing by the exact name.Named ExportsNamed exports let u · 4 min read · What is spread, default and rest parameters in JavaScript ? The default, spread, and rest parameters were added in ES6.
🌐
Itsourcecode
itsourcecode.com › home › how to export multiple functions in javascript
How to Export Multiple Functions in JavaScript
August 18, 2023 - ... In the importing file, use the import keyword followed by the function name to import the appropriate functions. In situations where you have multiple functions in a single file that you want to export, you can combine the export statements.