Parameters
A parameter is a variable in a method definition. To say it another way, a parameter is the variable in the declaration of the function, and it is found inside of the parenthesis.
File Location
We will be working in the following file:
javascript-library
└── 0-PreWork
└── 1-Fundamentals
└── 4-Functions
05-parameters.js <----You will be working in this file.
Sample Code
In the function below, we see two parameters: name
& type
.
function petNameAndBreed(name, type){
var petDetails = name + ", " + type;
console.log(petDetails);
return petDetails;
}
Arguments
We'll talk in the next module about arguments, but the following function calls show how the parameters work like variables. We put a different value in each time we call it:
petNameAndBreed("Johnny", "Tortoise Shell Cat");
petNameAndBreed("Sansa", "Bulldog");
Key Points
We'll get a lot more practice with parameters in the future. The key takeaways are these points:
Parameters are like variables.
Declared in the parenthesis of a function.
The arguments are the values that get assigned to the parameters when the function is called.
Last updated