Sikau

JavaScript · Day 24 · about 30 min

Parameters and return

Ingredients in, dish out.

Functions that take and give

A momo shop takes ingredients in (filling, number of plates) and hands a dish out. Functions can do the same: take values in through parameters and hand a result back with return.

Parameters: values in

function greet(name) {
  console.log("Namaste, " + name + "!");
}

greet("Sita");
greet("Ram");
function orderMomo(plates, filling) {
  console.log(`${plates} plates of ${filling} momo`);
}
orderMomo(2, "buff");

The rest of this lesson

  • return: a value outexplain
  • Return values flow backexplain
  • Predict the outputpredict
  • Calls inside callspredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript