Menu
Coddy logo textTech

Return

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 47 of 77.

The return statement in a function is used to specify the value or values that the function should produce as its output.

For example, the following function will output 100:

function functionName() {
	return 100;
}

To pass the value to a variable, write:

let number = functionName();

Now the number variable will hold 100 because this is what the function returned.

challenge icon

Challenge

Easy

Create a function called square that takes a single parameter n and returns its square. Then, call the function with the input value (given) and store the result in a variable called result. Finally, print the value of result.

Cheat sheet

The return statement specifies the value a function produces as output:

function functionName() {
	return 100;
}

To capture the returned value in a variable:

let number = functionName();

Try it yourself

let num = parseInt(inp); // Don't change this line
// Type your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals