Explanation Hoisting Javascript

Asked

Viewed 56 times

0

In Javascript, every variable that is declared with the keyword var is "high" (Hoisting) to the top of the execution context, right?

function testandoMsg (){
	let b = 'B';
	console.log(a);
	console.log(b);
	var a = 'A';
}

testandoMsg();

If the var is played to the top of the function because of Hoisting, because it gives Undefined on execution?

1 answer

1


In Javascript, every variable that is declared with the keyword var is "high" (Hoisting) to the top of the execution context, right?

You basically explained your question with that statement. Only the variable declaration suffers the Hoisting, not the assignment of values (this happens in run-time). Therefore, a variable declared valueless is Undefined.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.