Functions name reusable work and return values to the caller.

Functions

functions.js
function square(value) {
  return value * value;
}

const side = 5;
const area = square(side);

console.log("side=" + side);
console.log("area=" + area);

Follow the Function Call

  1. side starts at 5.
  2. square(side) sends 5 into the function.
  3. The function returns 5 * 5.
  4. area becomes 25.
  5. The program prints side=5 and area=25. | side | square result | | --- | --- | | 3 | 9 | | 5 | 25 | | 8 | 64 |
function call A function call runs the named function and can use the returned value in another expression.

Exercise: functions.js

Reproduce area=25 for side 5, then try side 3 and 8 and predict each area before running it.