advertisement
The return Statement in JavaScript
❌
Return Statement
A function operates on its parameters which might lead to some output values. This output needs to be displayed to the user or it needs to be sent back to the calling function. Java Script allows sending the result back to the calling function by using the return statement.
The return statement begins with the return keyword followed by the variable or value, which must be returned to the calling function. The return statement can also be used to halt the function's execution and return control to the calling function. This is required when a particular condition is false or unexpected results are likely during code execution.
Script that calculates the factorial of a number using a function and displays the output to the user.
Example 1: Simple Function Return
Example 2: Conditional Return
Example 3: Early Return
advertisement
Conversation
Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!
Join the discussion and share your insights now!
Comments 0