Returning Values
Functions in JavaScript can return a value using the return keyword. When a function is called and it encounters a return statement, it immediately stops executing the function and returns the specified value.
Here's an example of a function that adds two numbers and returns the result:
JAVASCRIPT
1function add(num1, num2) {
2 return num1 + num2;
3}
4
5const result = add(2, 3);
6console.log(result); // Output: 5xxxxxxxxxx// In JavaScript, functions can return values using the return keyword.function add(num1, num2) { return num1 + num2;}const result = add(2, 3);console.log(result);OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment


