Better way of handling function parameters in Javascript

Dhiman Das
May 23, 2021

--

Let’s say you have a function which has five parameters.

When you are going to call this function from another function, you have to follow the exact signature. But what if you accidentally interchange one of the parameters.

So logically, your code will not work the way you want. So how to solve this?

First way is you can send the parameters in exact format. But definitely you are not here to hear this line right? So what’s the other way?

You can actually create an object instead of a list of parameters. Let’s check the below screenshot

Now you don’t need to follow the exact order of parameters. Let’s check the below screenshot to get a more clear view.

Thanks for investing your time…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Dhiman Das
Dhiman Das

Written by Dhiman Das

A software developer, who also loves to read self-help book, love to do cycling, love to play music and also entered into the world of content writing.

No responses yet

Write a response