Return in JavaScript _ 2 Minute JS _ JavaScript Tutorials in Hindi [Part 16]

4K views Jul 5, 2023

The return statement in JavaScript is used to exit a function and return a value. The value that is returned can be any type of value, including a number, a string, an object, or even another function. The return statement can be used in any function, but it is most commonly used in functions that are designed to return a value. For example, the following function is designed to return the factorial of a number: Code snippet function factorial(number) { if (number === 0) { return 1; } else { return number * factorial(number - 1); } } Use code with caution. Learn more In this function, the return statement is used to return the value of the factorial calculation. The return statement is also used to exit the function when the factorial calculation is complete. The return statement is a powerful tool that can be used to control the flow of your JavaScript code. It can be used to exit functions, return values, and even break out of loops.

#Programming