Skip to content

return

In JavaScript, the return keyword ends the current function call and sends a value back to the caller. A bare return; returns undefined, and so does a function body that finishes without reaching a return. The statement is allowed only inside a function body, so a return at the top level of a script or ES module is a SyntaxError.

In an async function, the returned value resolves the promise the call produced. In a generator, return finishes the generator, and .next() reports the value with done: true. An arrow function with an expression body returns that expression without the keyword. Inside a try block, a finally block runs before the function actually returns.

The expression must start on the same line as return. With a line break after the keyword, automatic semicolon insertion ends the statement there, and the function returns undefined.

JavaScript return Keyword Syntax

A return statement can appear with or without a value:

Language: JavaScript Syntax
return;
return <expression>;

JavaScript return Keyword Examples

An early return ends the call before any discount is calculated:

Language: JavaScript
> function getDiscount(total) {
…   if (total < 50) {
…     return 0;
…   }
…   return total * 0.1;
… }
undefined

> getDiscount(30)
0
> getDiscount(120)
12

The early return ends the call for small totals, so the second return runs only for totals of 50 or more.

A line break right after return changes what the function returns:

Language: JavaScript
> function getGreeting() {
…   return
…     "Hello, Ada!";
… }
undefined

> getGreeting()
undefined

JavaScript return Keyword Use Cases

  • Sending a computed result back to the caller
  • Exiting a function early when an input is invalid or a result is already known
  • Ending a loop and its function at once from inside the loop body
  • Finishing a generator with a final value

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026