JavaScriptMedium
What are the potential issues caused by hoisting?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Hoisting can lead to unexpected behavior in JavaScript because variable and function declarations are moved to the top of their containing scope during the compilation phase. This can result in undefined values for variables if they are used before their declaration and can cause confusion with function declarations and expressions. For example:
js
console.log(a); // undefined
var a = 5;
console.log(b); // ReferenceError: Cannot access 'b' before initialization
let b = 10;
