Return Statement
A return statement sends a value back from a function to the code that called it, and immediately ends the function's execution.
General Programming
Without a return, a function performs its work but hands back nothing (in Python this is None, in JavaScript undefined). With one, the result can be stored or reused.
Syntax
return valueExamples
Python
def square(n):
return n * n
result = square(4)
print(result)Output:
16JavaScript
function square(n) {
return n * n;
}
console.log(square(4));Output:
16