Functions for JavaScripts
JavaScript functions are reusable blocks of code that can be declared, assigned to variables, passed as arguments and returned from other functions. Scope decides which variables a function can see, and closures let it remember its surrounding variables. This unit in the Functions and Scope stage underpins callbacks, modules and async code.
Stage: Functions and Scope · Part of the JavaScript roadmap · Last reviewed 19 November 2026
What to learn in Functions
- Write function declarations, expressions and arrow functions and know when each fits
- Use default parameters and the rest operator for flexible arguments
- Explain block scope versus function scope and the temporal dead zone
- Build a closure that keeps a private counter between calls
- Pass a callback to a higher-order function such as setTimeout
Functions interview questions
What is a closure in JavaScript?
A closure is a function bundled with references to the variables from the scope where it was created. It keeps access to them even after the outer function has returned. Closures are used for private state, factories and callbacks that remember context.
What is hoisting in JavaScript?
Hoisting means declarations are processed before code runs. Function declarations are fully available early, var variables exist but are undefined, and let and const are hoisted but cannot be used before their line, a gap called the temporal dead zone.
Where Functions fits in the JavaScript roadmap
Functions belongs to the Functions and Scope stage (beginner level), which takes about 28 hours. How code is organised.
Other units in this stage
Back to the full JavaScript roadmap