By the end of this lesson, learners will be able to:
When you define a function, you can specify parameters — placeholders for values you want the function to use.
When you call the function, you provide arguments — the actual values you pass to the function.
| Term | Description |
|---|---|
| Parameter | A named variable in the function definition |
| Argument | The actual value passed when calling the function |
function greetUser(name) {
console.log("Hello, " + name + "!");
}
name is a parameter – a placeholder for any namegreetUser("Anna"); // Hello, Anna!
greetUser("Liam"); // Hello, Liam!
"Anna" and "Liam" are arguments✅ Each time, the function personalizes the greeting.
Without parameters:
function greetAnna() {
console.log("Hello, Anna!");
}
With parameters:
function greetUser(name) {
console.log("Hello, " + name + "!");
}
✅ You can greet any user, not just Anna.
Functions can take more than one parameter:
function printFullName(firstName, lastName) {
console.log("Full Name: " + firstName + " " + lastName);
}
printFullName("Ada", "Lovelace"); // Full Name: Ada Lovelace
firstName and lastName are parameters"Ada" and "Lovelace" are argumentsfunction calculateArea(width, height) {
let area = width * height;
console.log("Area: " + area);
}
calculateArea(5, 3); // Area: 15
✅ You can reuse the function with different values anytime.
function greet(name) {
console.log("Hello, " + name);
}
greet(); // Output: Hello, undefined
undefined.