JavaScript: functions

A function groups reusable instructions and can receive parameters and return a result.

What you will learn

Minimal example

function addTax(price, rate) {
  return price * (1 + rate);
}

console.log(addTax(100, 0.1)); // 110

Define behavior once and call it with different arguments. A return value can be stored, displayed, or passed to another function.

Common mistakes