🧪 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); // 7Here, 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.
Leave a Reply