Explanation Hoisting JavaScript [duplicate]

0

In JavaScript, every variable that is declared with the var keyword is "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 var is thrown to the top of the function because of Hoisting, why does undefined run?

    
asked by anonymous 28.06.2018 / 14:24

1 answer

1
  

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

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

    
28.06.2018 / 16:10