Module 23: Functions and Scope

Lesson 1 of 5 · 15–25 minutes

Functions are values

🏠The everyday picture

A recipe card can be stored in a box, handed to a friend, or pinned to the wall. The card itself is a thing you can pass around, separate from actually cooking it.

📘What it really is

🖱️Try it

Create calc.js. Write functions addGst(price) (adds 18%) and addDelivery(price) (adds ₹40). Store them in an array steps, then loop over the array, applying each step to a starting price of ₹500 in turn. Print the result after each step.

✅Quick check

What's the difference between addGst and addGst(100)?

Show the answer

addGst is the function itself; addGst(100) runs it and gives the result.

Name a higher-order function you already use.

Show the answer

map, filter, reduce, sort or addEventListener: each takes a function as an argument.

← BackModule 23
ProLearners Assist