# JavaScript Return Values

> Learn how return values work in JavaScript, why every function returns undefined by default, and how the return keyword ends a function and hands back a value.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-06-09 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-return-values/

Every function returns a value, which by default is `undefined`.

![Undefined return value](https://flaviocopes.com/images/javascript-return-values/undefined-return-value.png)

Any function is terminated when its lines of code end, or when the execution flow finds a `return` keyword.

When [JavaScript](https://flaviocopes.com/javascript/) encounters this keyword it exits the function execution and gives control back to its caller.

If you pass a value, that value is returned as the result of the function:

```js
const dosomething = () => {
  return 'test'
}
const result = dosomething() // result === 'test'
```

You can only return one value.

To _simulate_ returning multiple values, you can return an **object literal**, or an **array**, and use a destructuring assignment when calling the function.

Using arrays:

![Destructuring using arrays](https://flaviocopes.com/images/javascript-return-values/destructuring-return-array.png)

Using objects:

![Destructuring using objects](https://flaviocopes.com/images/javascript-return-values/destructuring-return-object.png)
