Problem Statement
Which functions are hoisted in JavaScript?
Explanation
Hoisting means moving declarations to the top during compilation.
Only function declarations are hoisted, not function expressions or arrow functions.
That’s why you can call a declared function before writing it in code.
This behavior helps JavaScript interpret functions flexibly but can also cause confusion if misused.
Always declare clearly to keep your code readable.
Code Solution
SolutionRead Only
greet(); // Works!
function greet() {
console.log('Hello');
}
sayHi(); // Error
const sayHi = function() {
console.log('Hi');
};