CleanCode: How to use named parameters in JavaScript

If you’re familiar with named/keyword arguments in programming languages like Ruby, Python, and PHP 8, you might wonder if JavaScript offers the same functionality.
That’s an excellent question. Named parameters, also known as named arguments, signific…


This content originally appeared on DEV Community and was authored by Pierre-Henry Soria ✨

If you're familiar with named/keyword arguments in programming languages like Ruby, Python, and PHP 8, you might wonder if JavaScript offers the same functionality.
That's an excellent question. Named parameters, also known as named arguments, significantly enhance code readability. With named-parameter arguments, we can directly understand the purpose of each argument in a function call.

One way to achieve this is by using object destructuring on the function parameters.

Here’s an example:

const invertSentence = ({
  sentence,
  doesFormat = false
}) => {
  if (doesFormat) {
    return sentence;
  }

  // Logic…

  // Split the sentence into two segments
  const [stringOne, stringTwo] = sentence.split(. );

  // Rebuild the sentence
  const rebuiltString = `${stringTwo} ${stringOne}`;

  return rebuiltString;
};

Now, you can specify the required properties as “named arguments” when calling the function.

invertSentence({
  sentence: 'JS makes my job easier. Writing clean code avoid me from having a headache',
  doesFormat: false
});

Conclusion

In conclusion, JavaScript doesn't support keyword arguments natively, unlike PHP 8 and Python for instance. However, thanks to the power of object destructuring (introduced in ES6), we can structure our function signatures to accept arguments using their respective property names, thereby enhancing code readability.


This content originally appeared on DEV Community and was authored by Pierre-Henry Soria ✨


Print Share Comment Cite Upload Translate Updates
APA

Pierre-Henry Soria ✨ | Sciencx (2025-06-24T12:17:04+00:00) CleanCode: How to use named parameters in JavaScript. Retrieved from https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/

MLA
" » CleanCode: How to use named parameters in JavaScript." Pierre-Henry Soria ✨ | Sciencx - Tuesday June 24, 2025, https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/
HARVARD
Pierre-Henry Soria ✨ | Sciencx Tuesday June 24, 2025 » CleanCode: How to use named parameters in JavaScript., viewed ,<https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/>
VANCOUVER
Pierre-Henry Soria ✨ | Sciencx - » CleanCode: How to use named parameters in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/
CHICAGO
" » CleanCode: How to use named parameters in JavaScript." Pierre-Henry Soria ✨ | Sciencx - Accessed . https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/
IEEE
" » CleanCode: How to use named parameters in JavaScript." Pierre-Henry Soria ✨ | Sciencx [Online]. Available: https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/. [Accessed: ]
rf:citation
» CleanCode: How to use named parameters in JavaScript | Pierre-Henry Soria ✨ | Sciencx | https://www.scien.cx/2025/06/24/cleancode-how-to-use-named-parameters-in-javascript/ |

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.