JavaScript return Statement
Subject: JavaScript
The return statement in JavaScript is used inside a function to return a value to the place where the function was called. It also stops the function execution immediately.
Syntax
expressionis optional.- If no value is specified, the function returns 
undefinedby default. 
Example 1: Returning a Value
Example 2: Early Exit from Function
Example 3: Returning Without a Value
Example 4: Returning an Object
Best Practices
- Always place the return value on the same line as the 
returnkeyword. 
✅ Correct:
❌ Incorrect:
This will return undefined due to JavaScript's automatic semicolon insertion.
Key Takeaways
returnends the function and optionally sends back a value.- If omitted, 
undefinedis returned. - Use 
returnto exit functions early based on conditions. - Be cautious with newline placement after 
return. - Functions can return any data type—numbers, strings, arrays, objects, and more.