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();

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

TechLoons
TechLoons

Written by TechLoons

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

No responses yet

Write a response