MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Function Parameters and Return Values0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
7.1Defining and Calling Functions7.2Function Parameters and Return Values7.3Arrow Functions (Basic)
HomeTutorialsJavaScript for BeginnersFunction Parameters and Return Values
Arrow Functions (Basic)

Function Parameters and Return Values

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Functions receive inputs via parameters and send outputs back to the caller via return values. Mastering parameter defaults, rest parameters, and return semantics is essential for writing robust JavaScript functions.


1. Parameters vs. Arguments

While often used interchangeably in casual conversation, there is a clear distinction:

  • Parameters: The variable names listed in the function definition.
  • Arguments: The real values passed into the function when you invoke it.
1// 'base' and 'exponent' are PARAMETERS:
2function power(base, exponent) {
3 return base ** exponent;
4}
5 
6// 2 and 3 are ARGUMENTS:
7const result = power(2, 3);

2. The return Statement

The return statement does two things:

  1. 1
    It immediately stops the execution of the function.
  2. 2
    It sends the evaluated value back to the caller.
1function calculateTax(subtotal, taxRate) {
2 if (subtotal <= 0) {
3 return 0; // Exits early!
4 }
5 
6 return subtotal * taxRate;
7}
8 
9const tax = calculateTax(1000, 0.18); // 180
[!IMPORTANT] If a function does not have an explicit return statement (or has an empty return;), it automatically returns undefined!
1function doNothing() {}
2console.log(doNothing()); // undefined

3. Default Parameters (ES6)

What happens if a caller forgets to pass an argument? Without defaults, missing arguments become undefined. In ES6, you can specify default values directly in the parameter list:

1function createAccount(username, role = "Student", isActive = true) {
2 return {
3 username,
4 role,
5 isActive
6 };
7}
8 
9console.log(createAccount("sumit_dev"));
10// { username: "sumit_dev", role: "Student", isActive: true }

4. Variable Number of Arguments: Rest Parameters (...args)

What if you want to write a function that can accept any number of inputs (e.g. summing 3, 5, or 100 numbers)? Use the Rest Parameter (...):

1function sumAll(...numbers) {
2 // 'numbers' is a real JavaScript array!
3 let total = 0;
4 for (const n of numbers) {
5 total += n;
6 }
7 return total;
8}
9 
10console.log(sumAll(10, 20)); // 30
11console.log(sumAll(5, 15, 25, 35, 45)); // 125
Note
[!NOTE] The rest parameter must always be the very last parameter in the function definition!

5. Returning Multiple Values via Objects or Arrays

A function in JavaScript can technically only return a single value. To return multiple values, return an object or an array:

1function getMinMax(numbers) {
2 const min = Math.min(...numbers);
3 const max = Math.max(...numbers);
4 return { min, max };
5}
6 
7// Destructure the returned object:
8const { min, max } = getMinMax([14, 5, 82, 1, 99]);
9console.log(`Lowest: ${min}, Highest: ${max}`); // Lowest: 1, Highest: 99

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does a JavaScript function return by default if it lacks an explicit return statement?
Question 2
What is the difference between a parameter and an argument?
Question 3
What is the value of tax if invoked as calculateTotal(500) where the function is defined as function calculateTotal(price, tax = 0.1) { return price * tax; }?
Question 4
Which operator allows a function to collect an indefinite number of arguments into a single array?
Question 5
Can code written after a return statement in the same execution branch ever execute?
Next Lesson

Arrow Functions (Basic)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Defining and Calling FunctionsArrow Functions (Basic)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext