
π This article includes 2 downloadable practice files β
In this article
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.
Practice
Run the script and write a function that returns the EMI-free total for qty and rate.
π Practice files for this article
β¬ Download all 2 files (ZIP Β· 481 B)
- πjs-04-functions.jsLesson code file.β¬ JS Β· 287 B
- πjs-04-functions-output.txtOutput from our test run.β¬ TXT Β· 30 B
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.