JavaScriptEasy
Explain the concept of hoisting with regards to functions
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Hoisting in JavaScript is a behavior where function declarations are moved to the top of their containing scope during the compile phase. This means you can call a function before it is defined in the code. However, this does not apply to function expressions or arrow functions, which are not hoisted in the same way.
js
// Function declaration
hoistedFunction(); // Works fine
function hoistedFunction() {
console.log("This function is hoisted");
}
// Function expression
nonHoistedFunction(); // Throws an error
var nonHoistedFunction = function () {
console.log("This function is not hoisted");
};
