No default exports

Today, I wanted to touch quickly on an extremely opinionated JavaScript architecture/code authoring standards position I have.
Do not ever use default exports.
I’ve worked on projects that used a mix of default exports and collections of exports, and it gets really confusing, really fast.
import { formatCurrency } from ‘./formatCurrency.js’; import convertCentsToDollars from ‘./convertCentsToDollars.js’; Why is formatCurrency destructured, but convertCentsToDollars is not?
You might assume that convertCentsToDollars is the only export in its file, while formatCurrency is one of a few exports.


This content originally appeared on Go Make Things and was authored by Go Make Things

Today, I wanted to touch quickly on an extremely opinionated JavaScript architecture/code authoring standards position I have.

Do not ever use default exports.

I’ve worked on projects that used a mix of default exports and collections of exports, and it gets really confusing, really fast.

import { formatCurrency } from './formatCurrency.js';
import convertCentsToDollars from './convertCentsToDollars.js';

Why is formatCurrency destructured, but convertCentsToDollars is not?

You might assume that convertCentsToDollars is the only export in its file, while formatCurrency is one of a few exports.

And that could be the case. Or it could not!

And that’s exactly the point. The mix/match of default exports and object destructuring imports creates needless mental overhead and forces me to think about things that I shouldn’t have to.

If everything gets imported “the normal way,” I never have to think about how to import it.

Like this? A Lean Web Club membership is the best way to support my work and help me create more free content.


This content originally appeared on Go Make Things and was authored by Go Make Things


Print Share Comment Cite Upload Translate Updates
APA

Go Make Things | Sciencx (2025-05-06T14:30:00+00:00) No default exports. Retrieved from https://www.scien.cx/2025/05/06/no-default-exports/

MLA
" » No default exports." Go Make Things | Sciencx - Tuesday May 6, 2025, https://www.scien.cx/2025/05/06/no-default-exports/
HARVARD
Go Make Things | Sciencx Tuesday May 6, 2025 » No default exports., viewed ,<https://www.scien.cx/2025/05/06/no-default-exports/>
VANCOUVER
Go Make Things | Sciencx - » No default exports. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/05/06/no-default-exports/
CHICAGO
" » No default exports." Go Make Things | Sciencx - Accessed . https://www.scien.cx/2025/05/06/no-default-exports/
IEEE
" » No default exports." Go Make Things | Sciencx [Online]. Available: https://www.scien.cx/2025/05/06/no-default-exports/. [Accessed: ]
rf:citation
» No default exports | Go Make Things | Sciencx | https://www.scien.cx/2025/05/06/no-default-exports/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.