-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path24_return.js
22 lines (12 loc) · 1.42 KB
/
24_return.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// In JavaScript, the return keyword is used inside a function to return a value to the code that called the function. When a return statement is executed inside a function, it immediately stops the execution of the function and returns the specified value to the calling code.
// Here's an example of a function that uses the return keyword:
// function addNumbers(a, b) {
// return a + b;
// }
// This function is called addNumbers and it takes two parameters called a and b.The function uses the + operator to add the values of a and b together and returns the result using the return keyword.
// To use the addNumbers function and get the result, you can call it like this:
// var result = addNumbers(2, 3);
// console.log(result); // logs 5
// In this example, the addNumbers function is called with the values 2 and 3 as its parameters.The function adds those two values together and returns the result using the return keyword.The result is then assigned to a variable called result, which is logged to the console.
// The return keyword can be used to return any type of value from a function, including numbers, strings, booleans, arrays, objects, and even other functions.
// It's important to note that a function can only return one value. If you need to return multiple values from a function, you can use an array, an object, or another data structure to group the values together and return them as a single value.