Free course · Lesson 2 of 5
Control Flow & Functions
In this lesson you will
- Make decisions with if/else and strict equality
- Write functions, including arrow functions
JavaScript's if / else if / else and for /
while loops work as you'd expect. Functions can be written the classic way, or as
modern arrow functions — a shorter syntax used everywhere in current JavaScript.
- Classic function:
function greet(name) { return "Hi " + name; } - Arrow function:
const greet = (name) => `Hi ${name}`; ===compares value and type — always prefer it over the loose==.- Array methods like
.map()and.filter()often replace manual loops.
💡 Practical Skill: Reach for .filter() and .map() before
a manual for loop — they're shorter, and communicate intent more clearly.
const attendance = [18, 15, 20, 9, 17];const totalClasses = 20; const checkStatus = (classesAttended) => { const rate = (classesAttended / totalClasses) * 100; if (rate >= 80) return "Eligible for certificate"; if (rate >= 60) return "Needs make-up session"; return "At risk — contact student";}; attendance.forEach((classes, index) => { console.log(`Student ${index + 1}: ${checkStatus(classes)}`);});
Practice exercise
Write an arrow function that returns 'Pass' or 'Fail' for a mark, then use a loop to print the result for five marks.
Key takeaways
- Always compare with === and !==
- Functions turn repeated code into named, reusable steps
- Arrow functions are a short way to write small functions
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.