Parameters, Defaults, Rest, and Returns
Work with parameters, default values, rest parameters, and clear return values in small, readable functions.
Parameters, Defaults, Rest, and Returns is a free JavaScript Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro
Goal: Pass values into functions safely and return results clearly.
- Required vs default params
- Rest params
- Return values

Simple parameter
A parameter lets callers pass a value into your function.
// Simple parameters
function greet(name) {
// Make a message from the input
const message = "Hello, " + name + "!";
console.log(message);
}
greet("Ayla");

Default parameter
Use a default value so the function still works when an argument is missing.
// Default parameter
function welcome(name = "Guest") {
// If no name is given, "Guest" is used
console.log("Welcome, " + name);
}
welcome("Mina");
welcome();

Rest parameters
The rest parameter collects remaining arguments into an array. It must be last.
// Rest parameter: gather extra args into an array
function sum(...nums) {
// nums is an array of all arguments
let total = 0;
for (const n of nums) {
total = total + n;
}
return total;
}
console.log("Sum A:", sum(1, 2));
console.log("Sum B:", sum(1, 2, 3, 4));

Return values
Return a single clear result. Validate inputs first for safer code.
// Return a value clearly
function areaOfRectangle(w, h) {
// Validate simple inputs
if (typeof w !== "number" || typeof h !== "number") {
return 0;
}
// Compute and return the result
const area = w * h;
return area;
}
console.log("Area:", areaOfRectangle(3, 4));
console.log("Area bad:", areaOfRectangle("3", 4));

Tips for params & returns
Tips:
- Place the rest parameter last.
- Keep parameter lists short.
- Use defaults for common fallback values.
- Always return a predictable type.

Rest parameter quiz
Quick check: Rest syntax.

Recap
Recap: You used regular and default parameters, gathered extra args with a rest parameter, and returned clear results from functions.

Frequently asked questions
Is the “Parameters, Defaults, Rest, and Returns” lesson free?
Yes — the full text of “Parameters, Defaults, Rest, and Returns” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Parameters, Defaults, Rest, and Returns”?
Work with parameters, default values, rest parameters, and clear return values in small, readable functions. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Parameters, Defaults, Rest, and Returns” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Declarations vs Expressions, Arrow Basics
- Parameters, Defaults, Rest, and Returns
- this Basics; call/apply/bind (intro)