# Implicit Return

In JavaScript, a function can return a value to the code that called it. This value is the result of the function's execution. A function can return a value using the `return` keyword. When the `return` keyword is used, the function's execution stops and the value is returned

```javascript
function add(a, b) {
  return a + b;
}

let result = add(2, 3);
console.log(result); // Output: 5
```

An implicit return is a way of returning a value from a function without explicitly using the `return` keyword. This can be done by using arrow functions, which have a shorthand syntax that allows you to omit the `return` keyword when the function only has one expression.

```javascript
let add = (a, b) => a + b; 

let result = add(2, 3);
console.log(result); // Output: 5
```

In the example above the function `add` is an arrow function that takes two parameters `a` and `b`. The code inside the function `a + b` is the only expression inside the function, and it is implicitly returned.

An implicit return can also be done with the use of a single line function block, you don't need to use the return keyword and the curly braces if the function only has one line of code:

```javascript
function double(x) { return x*2 }
```

can be written as:

```javascript
const double = x => x*2;
```

It's important to note that implicit return only works when the function has a single expression, if you want to return an object, you will need to wrap it in parenthesis, like this:

```javascript
const myFunction = () => ({ key: 'value' });
```

In summary, an implicit return is a way to return a value from a function without explicitly using the `return` keyword, it can be achieved by using arrow functions and single line function blocks, it's a shorthand that can make the code more concise and easier to read.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demirels-organization.gitbook.io/javascript-tutorial/implicit-return.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
