224k views
2 votes
What is variable hoisting in JavaScript? Provide examples.

User HpTerm
by
4.7k points

1 Answer

0 votes

Answer:

before executing a code using javascript hoisting we can move any variable declaration to the top of the scope in a code.

Step-by-step explanation:

It is to be remembered that hoisting works with declaration not with initialization.

example:

//initializing a variable s

var s = 2;

t = 4

elem.innerHTML = s + " " + t; // Display s and t values

// initializing a variable for hoisting

var t;

User RGilkes
by
5.1k points