What is hoisting?

TechLoons
Jan 16, 2024

--

Photo by Juanjo Jaramillo on Unsplash

Hoisting is a JavaScript mechanism where variable and function declarations are conceptually moved to the top of their scope before code execution begins. However, variable assignments are not hoisted.

console.log(x); // Output: undefined (variable is declared but not assigned)
var x = 10;

function myFunction() {
console.log(y); // Output: undefined (function is declared but not assigned)
var y = 20;
}
myFunction();

--

--

TechLoons

Welcome to TechLoons, your go-to source for the latest tips and information on a wide range of topics.