Functions
Write and call functions, the three ways to define them, default and rest parameters, scope, hoisting, closures, callbacks, recursion and pure functions.
A function is a named, reusable block of code: you write the steps once and run them whenever you need them, with different inputs each time. Almost everything in JavaScript is built from functions: click handlers, array methods like map, timers, whole apps. This phase teaches them from the very first function greet() to the ideas interviewers love to ask about.
You'll learn how to declare and call functions, the three ways to write them (declarations, expressions and arrow functions), and how to accept inputs flexibly with default, rest and destructured parameters. Then come the rules that decide which variables a function can see (scope), why some code works before the line it's written on (hoisting and the temporal dead zone), and the most famous idea in JavaScript: closures, functions that remember where they were born.
Finally you'll pass functions to other functions (callbacks and higher-order functions), make a function call itself (recursion), and learn why pure functions with no side effects make code easier to test. This phase builds on Phase 1 (variables and types) and Phase 2 (operators, conditions and loops). Recursion and higher-order functions lead straight into Hectal's /dsa course.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.