Function Parameters and Arguments: Creating Dynamic JavaScript
Master JavaScript parameters and arguments to build dynamic, reusable functions. Learn how to pass data into your code to make your apps more flexible.

Previously in this course, we learned how to encapsulate blocks of code using writing-custom-functions-a-guide-to-javascript-code-reuse. While functions are great for organization, they are currently limited to doing the exact same thing every time they run.
In this lesson, we will make your functions truly dynamic by teaching them how to accept data from the outside world. This is the key to writing modular, production-grade code.
Understanding Parameters vs. Arguments
To pass data into a function, we use two related concepts: parameters and arguments. It is common for beginners to use these terms interchangeably, but there is a clear distinction:
- Parameters are the placeholders defined in the function's declaration. They act as local variables that will hold the values passed into the function.
- Arguments are the actual values you pass into the function when you call it.
Think of a function like a toaster. The "slot" where you put the bread is the parameter (it’s just a space waiting for something). The actual slice of sourdough you drop in is the argument.
Defining Parameters in a Function
When you define a function, you add parameters inside the parentheses (). Here is a simple example for our project, where we want to greet a user by name:
JAVASCRIPTfunction greetUser(name) { console.log("Hello, " + name + "!"); }
In this code, name is the parameter. It doesn't have a value yet; it simply tells the function, "Expect some data to arrive here, and I'll call it name while we're inside this block."
Passing Arguments to Functions
Now, to make the function do something, we call it and provide an argument:
JAVASCRIPTgreetUser("Alice"); // Output: "Hello, Alice!" greetUser("Bob"); // Output: "Hello, Bob!"
By changing the argument, the function produces a different result. This is how we achieve dynamic behavior without writing new functions for every single user.
Using Multiple Parameters

Functions aren't limited to a single input. You can define as many as you need, separated by commas. Let’s expand our dashboard project to include a function that calculates a task's priority status based on a title and a priority level.
JAVASCRIPTfunction formatTask(title, priority) { console.log("Task: " + title + " | Priority: " + priority); } // Calling with multiple arguments formatTask("Buy groceries", "High"); formatTask("Water plants", "Low");
When using multiple parameters, the order matters. JavaScript assigns arguments to parameters based on their position: the first argument goes to the first parameter, the second to the second, and so on.
Hands-on Exercise: The Greeting Utility
Let's apply this to your dashboard project. Create a function named displayWeather that accepts two parameters: city and temp.
- Define the function to
console.loga message like: "The weather in [city] is [temp] degrees." - Call the function three times with different cities and temperatures (e.g., "London", 15 and "Tokyo", 22).
- Check your browser console to verify the output.
Common Pitfalls

- Order Confusion: If you call
formatTask("High", "Buy groceries"), your output will be "Task: High | Priority: Buy groceries". Always ensure your arguments match the order defined in the parameter list. - Missing Arguments: If you define two parameters but only pass one argument, the missing one will be
undefined. For example,greetUser()would print "Hello, undefined!". We will look at how to handle this gracefully in future lessons. - Scope Confusion: Parameters are local to the function. You cannot access the
namevariable from outside thegreetUserfunction.
FAQ
Q: Can I use variables as arguments?
A: Absolutely! You don't have to pass raw strings or numbers. You can pass any variable, like formatTask(myTaskName, myTaskPriority).
Q: Is there a limit to how many parameters I can have? A: Technically, you can have many, but if you find yourself passing more than 3-4, it’s often a sign that you should group your data into an object instead (which we covered in introduction-to-objects-managing-complex-data-in-javascript).
Q: What happens if I pass too many arguments? A: JavaScript will simply ignore the extra arguments. It won't throw an error, but it won't do anything with the extra data.
Recap

- Parameters are the named placeholders in a function definition.
- Arguments are the actual values passed during a function call.
- You can pass multiple parameters by separating them with commas.
- The order of arguments must match the order of parameters.
Up next: We will learn how to use the return statement to get data out of your functions, moving beyond simple console logs.
Work with me

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

Laravel SaaS MVP & Multi-Tenant App Development
Launch your SaaS MVP on Laravel — multi-tenant, subscription-ready, and built by the engineer behind a platform serving 10,000+ paying users.


