Short answer
A return value is the data a function hands back to the code that called it, instead of only printing text or doing nothing. Python's tutorial says a function with no return still returns None. JavaScript's return statement makes the call evaluate to that value, or to undefined if the expression is omitted. A Java method declared void does not return a value at all.
Last verified against the sources listed below.
Key takeaways
- Return hands a value to the caller and stops the function at that statement.
- In Python, falling off the end of a function returns None. return with no expression does too.
- In JavaScript, a bare return yields undefined. Do not put a line break after return.
- A Java void method cannot return a value. Any other return type must match the declaration.
- Printing writes text to a stream. It is not a substitute for returning a value the caller can store.
- A React component is a function that returns markup, still the same idea of handing a result back.
What is return value is a question about the data a function hands back to the line that called it. Python’s tutorial separates that from printing. A function can write numbers as it runs and still have nothing useful for the caller to store.
The same idea shows up in JavaScript and Java, with different names for “nothing came back.” Programming paradigms differ in syntax. Returning a value is one of the shared moves.
What is a return value?
A return value is the result of a call, available to the code that invoked the function. In JavaScript, MDN’s return page says the statement ends function execution and specifies a value to be returned to the caller. In a plain function, the call evaluates to that value.
Python’s tutorial describes the statement the same way: return returns with a value from a function. The caller can bind that value to a name. In the tutorial’s second Fibonacci example, fib2 builds a list and returns it, so f100 = fib2(100) holds the list instead of only showing numbers on the screen.
Oracle’s Java tutorial says a method returns to its caller when it finishes its statements, reaches return, or throws an exception, whichever comes first. You declare the return type on the method. Inside the body, return sends the value. The getArea example returns width * height as an int.
Stopping matters as much as the value. MDN’s counter example shows that code after the return in that path does not run. Python notes that a return also skips a loop’s else clause. The function leaves at that line.
How does Python hand a value back?
Python hands the value back with return, and it still hands None back when you forget the line. The tutorial is explicit: return without an expression returns None, and falling off the end of a function also returns None.
The first Fibonacci function in that chapter prints numbers and has no return. The tutorial says newcomers may think it is a procedure. It still returns None. Printing fib(0) shows None, because a bare None is otherwise hidden by the interpreter.
That is the whole worked case in words. fib2 starts an empty list, appends each Fibonacci number while the value is below the limit, then returns the list. The caller stores the list. The printing version shows the series and leaves the caller with None.
Python’s print documentation describes a different job. print writes objects to a text stream, separated by sep and followed by end, and uses standard output when no file is given. The text appears. It is not the list, or the number, you can pass into the next call.
How do JavaScript and Java name an empty result?
JavaScript uses undefined when a return has no expression. Java uses void when the method is declared to return nothing. They are not the same feature, and neither one is Python’s None, but all three mark “do not treat this as a computed result.”
MDN says the expression is optional. If it is omitted, undefined is returned.
The page’s getRectArea example returns width * height when both sides are positive, and returns 0 otherwise. getRectArea(3, 4) is 12, and getRectArea(-3, 4) is 0. A missing expression would not be that 0. It would be undefined.
The page also warns about automatic semicolon insertion. A line break between return and the expression becomes a bare return, so the function yields undefined and the next line never runs as the result. Parentheses around a multiline expression keep the value attached. MDN marks return widely available since July 2015.
Oracle’s tutorial, written for JDK 8, says any method declared void does not return a value. It does not need a return, but it may use a bare return to leave early. Returning a value from a void method is a compiler error.
A non-void method must return a value of the declared type. You cannot return an integer from a method declared to return boolean.
Java can also return an object. The tutorial’s seeWhosFastest example returns a Bicycle. If the declared type is a class, the object must be that class or a subclass. The tutorial calls a subclass return type on an override a covariant return type.
How do return, print, and void compare?
Return gives the caller a value. Print writes text. Void, in Java, means the method is not allowed to give a value back.
| Form | What the caller gets | What else happens |
|---|---|---|
Python return value |
That value | Function stops. No expression means None |
Python print |
Not the printed text | Text is written to a stream |
JavaScript return |
The expression, or undefined |
Function stops. A line break can drop the value |
Java non-void return |
A value of the declared type | Required, or the method does not compile |
Java void |
No value | Bare return only, to exit early |
JavaScript can return a function. MDN shows magic returning calc.
Python does the same with a lambda: the tutorial shows a function that returns a function of x. The caller gets a callable, not a printed trace.
Where do people mix the channels up?
The common mistake is to print the answer and then try to use the call as if it were the answer. In Python that call is None unless you also returned the data. Tests and later lines then fail on None, not on the numbers that scrolled past.
A second mistake is a Java method that computes a result but is declared void, or the reverse: a non-void method that can finish without a return. The tutorial’s rule is mechanical. The declaration and the return have to match, and the type has to match.
A third mistake is JavaScript’s broken line after return. The function ends before the expression. The call looks empty because it is undefined. Keep the expression on the return line.
A React component is the same pattern in a UI file. React’s JSX guide says each component is a JavaScript function that may contain markup React renders, and that multiple elements have to be returned inside one parent tag. The SVG to JSX tool turns an SVG into that kind of component: a function whose return value is elements, not a separate image file.
Frequently asked questions
What is return value in Python if the function has no return line?
Python still returns a value. The tutorial says functions without a return statement return None, which is a built-in name. A return with no expression also returns None, and falling off the end of the function does the same. The interpreter usually hides a lone None, so the call can look like it produced nothing until you print the result. If you need the data later, return it explicitly and store the call in a name.
What is return value in Java when the method says void?
There is no value. Oracle's tutorial says a method declared void does not return a value. It may still use a bare return to leave the method early, but returning an actual value from a void method is a compiler error. A method that is not void must reach a return with a value whose type matches the declaration. You cannot return an int from a method declared to return boolean. The caller can use the result only when a type was declared.
Does a JavaScript return with no expression give zero?
No. MDN says that if the expression is omitted, undefined is returned. Zero would be a real number you chose to hand back, as in MDN's rectangle example, which returns 0 when width or height is not positive. A missing expression is not that choice. A line break between return and the expression is also rewritten so the function returns undefined and the next line never runs as the result. Keep the value on the same line, or wrap it in parentheses.
Is print the same as return?
No. Python's print writes objects to a text stream, separated by a separator and followed by an end string, defaulting to standard output. The caller does not receive the printed text as the function result. Return is how the result gets back into the caller's code so it can be stored, passed on, or tested. A function can print and also return, but the printed line and the returned value are different channels.
Can a function return another function?
Yes. MDN shows a function whose return value is another function, and Python's tutorial shows a lambda used the same way: a function that returns a function of x. The caller receives something it can call later. Java can return an object reference, including a subclass of the declared return type, which the tutorial calls a covariant return type. The thing handed back does not have to be a number or a string.
Sources
- 4. More Control Flow Tools · Python Software Foundation, 2026
- Built-in Functions, print · Python Software Foundation, 2026
- return · MDN, 2026
- Returning a Value from a Method · Oracle, 2026
- Writing Markup with JSX · React, 2026