CodingNeed.

3 · Work with collections · 8 MIN

Reuse a function

Functions turn inputs into outputs.

A parameter is a local name for an input. Calling a function supplies an argument. return gives the caller a result; console.log only displays something. Small functions with a clear contract are easier to reuse and test.

A small machine takes an ingredient, performs one operation, and gives you a result.

Read the example

function double(n) {
  return n * 2;
}
console.log(double(4));
Check the expected output
8

Your challenge

Return the larger of input.a and input.b. Equal values should return that value.

Common trap

Logging an answer does not return it to a caller.

Next lesson: Keep an ordered list →

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.