🎯 Learning Objectives
By the end of this class, students will be able to:
- Understand what functions are and why we use them.
- Create and call functions correctly.
- Use parameters and arguments.
- Use the return keyword to send back values.
- Understand function scope (basic).
- Write real-life programs using functions.
1. What Are Functions?
A function is a reusable block of code that performs a specific task.
💬 Easy Example (Real Life):
- The calculator + button is a function.
- The washing machine start button runs the same function every time.
- Calling pizza shop → same "order-taking" function runs for every customer.
📘 Without function:
console.log("Hello Ali");
console.log("Hello Sara");
console.log("Hello Hamza");
📘 With function:
function greet() {
console.log("Hello");
}
greet();
greet();
greet();
✅ Cleaner
✅ Reusable