Parameters and Arguments

These two terms started out with different meanings but have been used interchangeably so much that there are now quite a few places where they are defined as having the exact opposite of their original meanings. I can remember back in the late 1970s or early 1980s being taught that arguments are the placeholders that you provide within the definition of a function and that parameters are the values passed in a particular call to that function. You can now easily find places that give the exact opposite definition.

This confusion means that there are even programming languages that define the terms one way around in one spot and the opposite way around in another. An example of this is with JavaScript.

With JavaScript a function is defined as follows:

myfunc = function(nam1, nam2, nam3) {

Now using what I remember being taught the placeholders - nam1, nam2, and nam3 in this example - are the function arguments that are used within the function definition and which will be replaced by the corresponding parameter values passed to the function when it is actually called.

This naming convention is supported by the name of a property that all JavaScript functions have - the arguments[] property. In JavaScript you can leave out the placeholder names in the definition of the function and reference the placeholders via arguments[] as if the function had been defined as:

myfunc = function(arguments[0], arguments[1], arguments[2]) {

Of course you wouldn't actually define the function that way but you can reference the placeholders arguments[0] etc as if the function was defined that way regardless of what placeholder names are defined or even if none are defined at all at the top of the function definition like this:

myfunc = function() {

This means that within the JavaScript code itself JavaScript refers to the placeholders within the definition of the function as arguments - just as I remember learning so long ago. Just because the arguments[] placeholders are not defined in the first line of the function definition doesn't mean they are not placeholders since are still being used within the function definition in place of the values passed to the function and cannot be referenced from outside of the function definition (exactly the same as the named placeholders in the top line of the definition).

The JavaScript standards specify that a function is defined using the following structure:

function Identifier ( FormalParameterListopt ) { FunctionBody }

So the standards are referring to the placeholders within the function definition as parameters. In addition all the references to passing values when the function is called refer to those values as arguments.

The simplest explanation that I can think of for this confusion is that those responsible for the early versions of JavaScript used the naming convention that I learnt while those responsible for the current standards learnt the opposite and so have written the standards their way while being unable to change the naming convention already used in the language itself to match - since by their reasoning the placeholder list used within function definitions ought to be called parameters[] and not arguments[] - but by the time they were in charge of the standards it was too late to change it.

That there are now two completely opposite ways in which the difference between arguments and parameters are defined would be of concern if it actually made any difference as to which are which. Most people now simply use the two terms interchangeably with their preferred term being used to mean both. Only in computer classes are you likely to find the distinction still being made between the two and there it is simply a matter of finding out which of the two conventions that the teacher is using so that you know which way around to apply the terms in their class.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow