Return Functions

Last Updated: 22nd October 2025


  • A return function sends data back to the caller.
  • When return is used, the function stops executing and passes the value after return to where it was called.
  • You can return numbers, strings, objects, arrays, or even other functions!

Hinglish Tip 🗣: return ka matlab — “yeh value function ke bahar bhej do”.


✏️ Basic Syntax

function functionName() {
  return value;
}

Example 1:

function add(a, b) {
  return a + b;
}

let result = add(2, 3);
console.log(result); // Output: 5

Example 2:

function createUser(name, age) {
  return {
    username: name,
    userAge: age,
  };
}

console.log(createUser("Riya", 22));
// Output: { username: 'Riya', userAge: 22 }

Example 3:

const multiply = (x, y) => x * y;

console.log(multiply(5, 3)); // Output: 15

💡 If your function has only one expression, you can skip and return keyword.


⚠️ Important Notes

  • Every function returns something — if not explicitly, it returns undefined.
  • Once a return statement executes, the function stops immediately.
function checkMe() {
  console.log("This will run");
}

console.log(check()); // Output: undefined

function check() {
  return "Done!";
  console.log("This will never run");
}

console.log(check()); // Output: "Done!"

💡 Quick Practice

  • Create a function square(num) that returns the square of a number.
  • Write a function getFullName(first, last) that returns full name.
  • Make a function makeMultiplier(x) that returns another function which multiplies its input by x.
  • Exercise Set 1
  • Exercise Set 2