Why the return statement matters: it sends a value back to the caller.

Learn how the return statement makes functions talk to the rest of your code. When a function finishes, return hands back a value you can store, display, or feed into further calculations. It's the bridge that keeps code modular, letting you compose small tasks into reusable blocks. It's simple and readable.

Let me explain a small but mighty idea in programming: the return statement. It’s one of those fundamentals that shows up in every language—Python, JavaScript, Java, C#, you name it. And yet, it’s easy to overlook how much power sits right there, waiting to be tapped. If you’re learning with Revature’s curriculum, you’ll notice that a lot of the code you write is really about building little machines that take in something, do something with it, and hand back a result. The return statement is how that “hand back” happens.

What, exactly, does return do?

Here’s the thing: a function is like a tiny factory. You feed it inputs, it performs its job, and then, if you want, it hands you something back. That “hand back” is the value that the return statement sends to the part of your program that called the function. Without a return, a function can still do things—print something, modify a variable in place, or update a collection—but it doesn’t provide a fresh piece of data to be used elsewhere. The return statement is the bridge between the function and the rest of your code.

Think about it like this: you’re at a bakery. You tell the baker what you want, and after a moment, you get a bag containing exactly what you ordered. The bag is the return value. If the baker just stood there and didn’t hand you the bag, you wouldn’t be able to enjoy the cookies or share them with a friend. In code, the moment you use return, you’re receiving a result you can store, display, or feed into another calculation.

A simple example that clicks

Let’s keep it concrete with a few tiny examples. In Python, a function that adds two numbers might look like this:

def add(a, b):

return a + b

result = add(5, 7)

print(result) # 12

That return a + b line is doing the heavy lifting. When add runs, it computes the sum and hands that sum back. The calling code, result = add(5, 7), captures that value, and then we can use it again anywhere we like.

In JavaScript, the pattern is the same, just with a different flavor of syntax:

function sum(x, y) {

return x + y;

}

let total = sum(2, 3);

console.log(total); // 5

Again, the function receives inputs, performs its job, and returns the result to the caller. The return value becomes total, the thing we can stash in a variable or use in further steps.

A quick look at Java or C#

If you’re dipping into statically typed languages like Java or C#, the idea is identical, though the language constrains the kinds of values you can return. In Java:

public int multiply(int a, int b) {

return a * b;

}

int product = multiply(4, 5);

System.out.println(product); // 20

In C# you’ll see the same pattern:

int Square(int n) {

return n * n;

}

int result = Square(6);

Console.WriteLine(result); // 36

The core takeaway: return is the formal handshake that passes data from inside a function to the outside world. It’s not just about ending the function; it’s about delivering something useful to the rest of your program.

Between ending a function and sending a signal

Sometimes people mix up the idea of “ending” with “returning.” You’ll hear statements like, “the function ends here.” Sure, the function finishes when it hits a return (or when it reaches the end of its block, in languages that allow that), but what matters more is what happens at that moment. If you think of a function as a story, return is the moment you publish the ending and pass the outcome to the reader.

This distinction matters in real code. If a function has a return statement, other parts of your program can rely on getting a value back. If you drop out without returning anything, you’re signaling that no new data will come from that function. In languages with explicit return types, you’ll often see the return type declared in the function signature, and the body must deliver a value of that type. That type-safety helps prevent a lot of bugs, especially once projects grow and teams scale.

A few handy analogies

  • The vending machine: you insert money, pick a product, and the machine dispenses a result. The result is the item you receive; the return statement is the system that makes that handoff explicit.

  • A mailroom courier: you drop off a request, someone fetches it, and then a letter with the answer is delivered back to you. The return value is the answer you receive.

  • A recipe: you mix ingredients and, when finished, you produce a dish that you serve back to the diner. The return is the finished dish that goes to the table.

Why this matters for real projects

In a typical Revature-style project, you’ll be stitching together several functions to build something bigger. Returning a value lets you:

  • Compose operations: one function can feed data into another, building up layers of functionality.

  • Test pieces in isolation: you can call a function with known inputs and check that the returned value matches your expectations.

  • Reuse logic: a function that returns a value can be dropped into many spots in your codebase, rather than rewriting the same calculation over and over.

  • Keep responsibilities clear: functions that return data stay as data providers, while those that perform side effects (like printing or updating a UI) can live separately.

A few frequent pitfalls to keep you on track

  • Forgetting to return anything at all: some learners start a function, do a bunch of stuff, but never hand back a value. The caller ends up with nothing useful and often with a null or None in languages that support it.

  • Returning the wrong type: if you declare a function to return an integer, returning a string or a complex object can cause headaches down the line.

  • Early returns that choke readability: it’s tempting to exit a function early under certain conditions, but it can make the flow harder to follow. balance clarity with efficiency.

  • Assuming return ends the whole program: returning from a function stops that function, not the entire program. The code that called it may still run other paths or catch the value and continue.

  • Confusing print/log with return: printing something is not the same as returning a value. A function should either return data or perform a side effect, but if you need both, do one in the function and handle the other outside.

Sound habits to keep in mind

  • Be explicit about what you return: if a value is essential for downstream steps, make sure you return it and document what it represents.

  • Keep the function focused: aim for single-responsibility functions that take inputs and return outputs. That clarity makes it easier to reuse and test.

  • Use meaningful names for functions and return values: a name like computeTotal or getUserScore helps others understand what’s flowing back from the function.

  • Consider the caller’s perspective: when you write a function, think about how it will be used. Will someone store the result in a variable, pass it to another function, or use it to decide what to do next?

A quick tour of the concept across languages

  • Python favors simplicity. A function can return almost anything: numbers, strings, lists, objects, or even None to signal “no value.”

  • JavaScript treats return as a way to send a value from a function to the caller, with the option of returning undefined if there’s nothing to send.

  • Java and C# keep you honest about types. You declare what a function will return, and the compiler helps catch mismatches before your code runs.

A practical mindset you can adopt today

When you write a function, start by asking: “What value should the caller receive?” If the answer is a number, a string, or a more complex structure, plan your return accordingly. If your function’s job is more about action than data, you might decide to return nothing (a void in languages that support it). Either way, make your intent explicit, and let the caller know what to expect.

As you work on projects and tackle more complex features, you’ll see how the return statement underpins modular design. It’s the tiny lever that makes your code adaptable, testable, and easier to reason about. That’s why so many developers treat it as a cornerstone, not just a line to type.

Connecting back to the bigger picture

If you’re exploring programming through the lens of Revature’s curriculum, you’ll notice how often you’ll rely on functions that return values. From data processing pipelines to tiny utilities that clean up user input, the ability to return a result is what turns a collection of steps into something purposeful. It’s the bridge from thinking in steps to building reliable, reusable components.

A final nudge of clarity

Let’s wrap with the simplest truth: the main use of the return statement is to pass a value back to the caller. It’s how a function communicates its outcome. It’s how you turn computation into something that other parts of your code can stand on and build from. When you see return in your editor, remember: you’re not ending a task in isolation—you’re delivering a result that can power the next move in your program.

If you ever feel a little stuck, try this quick exercise: write a small function that takes a list of numbers and returns the largest one. Then call it with different lists, and print the results. Notice how the value you get back from the function becomes the thing you work with next. That flow—input, process, return—is the heartbeat of real-world programming. It’s simple, elegant, and incredibly powerful. And it’s a skill you’ll reach for again and again as you build more, learn more, and create more sophisticated software.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy