
JavaScript return Statement - W3Schools
The return statement stops the execution of a function and returns a value. Read our JavaScript Tutorial to learn all you need to know about functions. Start with the introduction chapter about JavaScript Functions and JavaScript Scope. For more detailed information, see our Function Section on Function Definitions, Parameters, Invocation and ...
return - JavaScript | MDN - MDN Web Docs
Mar 13, 2025 · In a plain function, the call to that function evaluates to the return value. In an async function, the produced promise is resolved with the returned value. In a generator function, the produced generator object's next() method returns { done: true, value: returnedValue }.
How To Use Return in JavaScript? - GeeksforGeeks
Feb 17, 2025 · In JavaScript, the return statement is used to specify the value that a function should produce when it is called. It helps in controlling the flow of execution and provides meaningful outputs from functions. Understanding how return works is important for writing efficient and reusable code. What is the return statement?
JavaScript Return Statement - GeeksforGeeks
Feb 7, 2025 · The return statement in JavaScript is used to end the execution of a function and return a value to the caller. It is used to control function behaviour and optimise code execution. Syntax. Expression Evaluation: The expression inside the …
How to return values in javascript - Stack Overflow
May 4, 2011 · You can return an array, an object literal, or an object of a type you created that encapsulates the returned values. Then you can pass in the array, object literal, or custom object into a method to disseminate the values.
javascript - When should I use return? - Stack Overflow
Jun 2, 2013 · return is used to send a value back to where's it's called from. You use it if you want to return a value. If you don't have a return statement, it's the same as return undefined. console.log returns undefined, so return console.log(text) returns undefined. So, only return if you want to get a value from the function.
JavaScript Return Statements - freeCodeCamp.org
Jan 21, 2020 · When a function return s a value, the value can be assigned to a variable using the assignment operator (=). In the example below, the function returns the square of the argument. When the function resolves or ends, its value is the return ed value. The value is then assigned to the variable squared2.
How to use a return value in another function in Javascript?
Jul 12, 2017 · Call the function and save the return value of that very call. // do something. return "testing 123"; You can make this call from another function too, as long as both functions have same scope. For example: var test = firstFunction(); . alert(test); Demo. Why not just alert(firstFunction())?
The Return Statement in JavaScript - CodingNomads
With this in mind, you can define your function with a parameter and a return statement. You give the function something, and it gives you something back. It becomes nicely self-contained. It has clearly defined inputs and outputs: Having clearly defined inputs …
JavaScript Return Statements – TheLinuxCode
Dec 11, 2024 · Return statements are critical in JavaScript for functions to send data back to the caller. When executed, they stop function execution and return a value to the calling code. This enables reusable logic that can calculate, manipulate, or process data in …