“`javascript
function gst(amount, rate = 0.18) {
return Math.round(amount * rate * 100) / 100;
}
const fyLabel = (y, m) => {
const s = m < 4 ? y - 1 : y;
return `FY ${s}-${String(s + 1).slice(2)}`;
};
gst(1000); // 180
fyLabel(2027, 2); // "FY 2026-27"
```
Arrow functions ((a, b) => …) are shorter and common when passing functions to other functions, as you’ll see with arrays next lesson. A one-line arrow can skip braces and return: const double = x => x * 2;
Functions are values
You can store them in variables, pass them as arguments (button.addEventListener("click", fn)) and return them, which is what makes array methods and event handling work.
💡 Name functions after what they return or do: gst(), fyLabel(), formatRupees(). Good names make code read like sentences.
Practice
Run the script and write a function that returns the EMI-free total for qty and rate.