Review: Function Returning a Value

In JavaScript, a function returns a value by returning the value in the "return" statement to where the function was called. For example:

sum = add(a,b)

When we call the add(a,b) function and it executes its return statement, that returned value will be stored in the sum variable.

return

The return statement ends function execution and specifies a value to be returned to the function caller.


Source: Mozilla, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.