Parameters and Arguments

ליאור נכתב על ידי ליאור לביא, עודכן בתאריך 03/11/2023

When discussing code informally, the terms "parameter" and "argument" are often used interchangeably, almost as if they are synonyms. So, to bring some clarity, I thought it would be helpful to define the difference between these two terms.

Parameter

The term "parameter" describes the part in the signature of a function or method that specifies what data it expects to receive. In the following example, the expressions firstName and lastName are parameters of the static function getFullName.

public class Person{

    public static String getFullName(String firstName, String lastName){

        return firstName + ' ' + lastName;

    }

}

Argument

The term "argument" describes the actual values passed to the function when it is called in the code. In the following example, the expressions "Bilbo" and "Baggins" are arguments passed to the static function getFullName of the class Person.

String fullName = Person.getFullName('Bilbo', 'Baggins');

System.debug(fullName);    //Returns 'Bilbo Baggins'

A convenient way to remember the distinction between parameters and arguments is:

Parameter - Placeholder for passed values.

Argument - Actual value.