Search⌘ K

Return Statements

Explore how to use return statements in JavaScript functions to send values back, stop function execution early, and manage scenarios without explicit returns. This lesson helps you apply these concepts to create more effective functions.

Introduction

There’s one more powerful feature of functions. The return statement. In addition to accepting values in through arguments, a function can send something back out.

Here’s how that works.

Node.js
function add10(number) {
let newNumber = number + 10;
return newNumber;
}
let fifteen = add10(5);
console.log(fifteen); // -> 15

Breakdown

We give add10 a value of 5 when we call it. Inside the function, a new variable newNumber is created, which is equal to what was passed in plus 10.

We then return newNumber ...