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. This is lesson 2 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 3 lessons in total.
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.

Learn JavaScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 59
- Lessons
- 200
Frequently Asked Questions
Is the “Parameters, Defaults, Rest, and Returns” lesson free?
Yes — any 3 lessons of the JavaScript Academy learning path, including “Parameters, Defaults, Rest, and Returns”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 3.
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)