Logo

dev-resources.site

for different kinds of informations.

How I do: export/import?

Published at
1/12/2025
Categories
beginners
javascript
learning
coding
Author
aadswebdesign
Author
13 person written this
aadswebdesign
open
How I do: export/import?

(First, it's about of how I do things, no must(not) do this or that here!)

I know there are many more ways to deal with javascript module export/import but this is of how I use it mostly!

EXPORT

How I'm not doing it and why?

function foo(){}
function bar(){}
function other(){}
export {foo,bar,other}
Enter fullscreen mode Exit fullscreen mode

At this way, the file has to be maintained. As soon as there are functions changing/added or removed you have to spend time to update this list X

How I do it then and why?

export function foo(){}
export function bar(){}
export function other(){}
Enter fullscreen mode Exit fullscreen mode

That might be clear, there is nothing to be maintained here V

IMPORT

It depends, if there are only one or two functions to be imported then I do it this way:

import {foo,bar} from './path/to/let/say/functions.js';
Enter fullscreen mode Exit fullscreen mode

If it is more then that, same story as by export. It has to be maintained and there is no need for that. X

How I do it then and why?

import * as FT from './path/to/let/say/functions.js';
//using it
FT.foo()
FT.bar()
FT.other()
Enter fullscreen mode Exit fullscreen mode

This way, it is always up-to-date, and no maintenance required V

Β About wildcard/namespace

I make sure it is in uppercase ,short and reflects the imported filename

So in this example FT is short and reflects the imported file Func-Tions.js

That's it about my use of javascript module export/import.

My first post here and I have more in mind but for another time!

coding Article's
30 articles in total
Favicon
A Beginner’s Guide to Building GraphQL APIs with Apollo Server
Favicon
Day 1080 : Tuff
Favicon
Supercharge Your JavaScript Agents with Firecrawl in KaibanJS
Favicon
DEPLOYING A WEB APPLICATION WITH ARM TEMPLATE AND AZURE CLI
Favicon
Digital Warm Up
Favicon
The Ever-Evolving Tale of Intelligence, from Symbolic Systems to Generative Ai
Favicon
Unlock Your Coding Potential with the GitHub Copilot Global Bootcamp!
Favicon
Day 1079 : Price I'll Pay
Favicon
How to Implement Authentication in React Using JWT (JSON Web Tokens)
Favicon
Understanding Lists in Python
Favicon
Concurrency in C++: Mitigating Risks
Favicon
GUI Design with JavaFX Layout Managers
Favicon
Responsively App: The Ultimate Tool for Web Developers on Windows
Favicon
Python Find in List: A comprehensive guide
Favicon
Introduzione alla Programmazione in Java: Guida per Principianti | Introduction to Java Programming: A Beginner's Guide
Favicon
CREATING A ROCK, PAPER, & SCISSORS GAME IN PYTHON
Favicon
How I do: export/import?
Favicon
Whats your TECH stack ?? How did you get into that??
Favicon
Why Facing Your Fears Makes You a Cool (and Confident) Developer
Favicon
Greedy Algorithm With Examples
Favicon
Day 1078 : Proceed
Favicon
Building Developer Communities: The Key to Growing and Nurturing a Web Development Tribe
Favicon
A Beginner Story
Favicon
Top 14 GitHub Data Risks: Data Loss Scenarios and How to Prevent Them
Favicon
Built a Responsive Calculator with JavaScript by Muhammad Kashif Pathan
Favicon
How Do You Use Encapsulation with Micronaut Annotations?
Favicon
What __init__.py has to do with Python?
Favicon
Top 10 Programming Languages to Learn in 2025 πŸ–₯️
Favicon
Top 10 Cybersecurity Companies in India 2025
Favicon
πŸŽ‰ Simplify Laravel CRUD Operations with Ease! πŸš€

Featured ones: