← Home

What Is a Return Statement?

· 1 min read

πŸ§ͺ Concept:

A return statement sends a value back from a function. Instead of just doing something, the function gives you something back β€” like a vending machine for code.

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

let sum = add(3, 4);
console.log(sum); // 7

Here, the function adds the numbers and returns the result. You can store that result, use it in other code, or pass it to something else.

🧰 Why It Matters:

Returning values lets your functions do more than just print things β€” they can calculate, combine, transform, and share results with the rest of your program.

πŸŽ‰ Quick Challenge:

Write a function that returns your favorite emoji:

function getEmoji() {
  return "🌈";
}

console.log(getEmoji()); // 🌈

🧠 Fun Analogy:

A return statement is like a reply in a conversation. You ask a function for something β€” and it talks back.

πŸ“š Further Reading:

β–ͺ MDN Docs – return
β–ͺ W3Schools – JavaScript Return Statement

Subscribe to my feed to follow along. I’ll keep the lessons short and sweet.

What Is a Function Parameter?