
How to return values in javascript - Stack Overflow
May 4, 2011 · JavaScript passes a value from a function back to the code that called it by using the return statement. The value to be returned is specified in the return keyword.
JavaScript return Statement - W3Schools
// Call a function and save the return value in x: var x = myFunction(4, 3); function myFunction(a, b) { // Return the product of a and b return a * b;}
How do I set a javascript variable to the return of an inline function …
Jan 19, 2017 · The solution is to define the function and then invoke it (by adding the extra parentheses at the end): var x = ( function() {return true;} ) ();
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 · The return statement in JavaScript is used to end a function execution and send a value back to where the function was called. It allows the function to provide useful results, like numbers, strings, or objects, that can be used in other parts of the code.
Function return values - Learn web development | MDN - MDN Web Docs
Apr 11, 2025 · Some functions don't return a significant value, but others do. It's important to understand what their values are, how to use them in your code, and how to make functions return useful values. We'll cover all of these below.
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
Reduce in javascript with initial value - Stack Overflow
Mar 26, 2021 · Here is the small-fixed version which returned 112 as expected. //console.log(accumulator); if( currentValue % 2 === 0) { accumulator += currentValue; //return accumulator; return accumulator; This is the syntax provided by MDN for using an initial value: [0, 1, 2, 3, 4].reduce((accumulator, currentValue, currentIndex, array) => {
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 …
Understanding Return Values in JavaScript Functions - Codequick
When working with JavaScript functions, you may encounter the concept of return values. A return value is the value that a function sends back to the code that called it. It allows you to retrieve …