r/learnjavascript • • Sep 06 '26

How should I handle optional parameters with database defaults?

I'm writing a service function for a personal project

Right now I have something like

export async function createApplicationService(
  userId,
  companyName,
  role,
  appliedDate,
  status,
  salary,
  link,
  nextAction
)

The only fields that I really want to require are companyName and salary The other fields have default values defined in my database, so I don't want the user to have to explicitly pass them every time.

What's the best way to structure this so that I only insert the parameters that were actually provided, while letting the database handle the defaults for everything elseI'm writing a service function for a personal project where I'm creating an application tracking system.
Right now, I have something like:
export async function createApplicationService(
userId,
companyName,
role,
appliedDate,
status,
salary,
link,
nextAction
)

The only fields that I really want to require are companyName and salary. The other fields have default values defined in my database, so I don't want the user to have to explicitly pass them every time.
What's the best way to structure this so that I only insert the parameters that were actually provided, while letting the database handle the defaults for everything else

12 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/Disastrous_Cow_4149 Sep 06 '26

Ohhhhh that clicks something . Thank you veryy muchh man .

0

u/azhder Sep 07 '26

Clicks what? Remember how all those event listeners in browsers send you a single event object? That object can be extended with new fields, old ones can be deprecated and removed. You will not deal with a long list of positional parameters in function calls.

Besides, if every function takes a single object and returns another object, you can even chain them, the result of one be the input of the other.