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

Undefined return value

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

When 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:

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

Using objects:

Destructuring using objects


Download my free JavaScript book!

But.. wait! Don't stop here.

I created a premium training program that will transform you, quickly, into an excellent JavaScript developer. Practical lessons to learn the 80% of the JavaScript that you need, in 20% of the time!

⬇️ ⬇️ ⬇️

Sign up to the JavaScript Course now!

⬆️ ⬆️ ⬆️