![]() |
The It can be used to return a specific value, variable, or expression to the caller. If no value is provided, the function returns Syntax: return value;
JavaScript return Statement ExamplesExample 1: This code defines a function `Product(a, b)` that takes two parameters `a` and `b`. It returns the product of `a` and `b` by multiplying them. Then, it calls the `Product()` function with arguments `6` and `10` and logs the result, which is `60`.
Output 60 Example 2: Here, we will return multiple values by using the object and we are using ES6 object destructuring to unpack the value of the object. Here, the code defines a function `Language()` that returns an object containing three properties: `first`, `second`, and `Third`, each storing a string value. Then, it uses object destructuring to assign these properties to variables `first`, `second`, and `Third`. Finally, it logs the values of these variables.
Output HTML CSS Javascript |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |