Understanding Named Arguments

Learn about named arguments and how they help developers enter data in functions and OOP.

Named arguments represent a way to avoid confusion when calling functions or methods with a large number of arguments. This not only helps avoid problems with arguments being supplied in an incorrect order but also helps us skip arguments with defaults. In this lesson, we will learn how to apply named arguments to improve the accuracy of our code, reduce confusion during future maintenance cycles, and make our method and function calls more concise. We start by examining the generic syntax required to use named arguments.

Named argument generic syntax

In order to use named arguments, we need to know the names of the variables used in the function or method signature. We then specify that name, without the dollar sign, followed by a colon and the value to be supplied, as follows:

Get hands-on with 1200+ tech skills courses.