You are probably wondering what this image even means. Hoisting, in a sense, is like having all your stuff in place before you even using them.

Hoisting is javascript putting all the variables and function declarations to the top of the scope that it belongs to.

Let’s say we write the following the code:

	console.log('value of a: ', a);
	var a = 1;

The first line will print “value of a: undefined”. But how does it know that a is undefined. Here is what hoisting does:

var a;
	console.log('value of a: ', a);
	a = 1;

Every var variable gets pushed to the top of whatever scope the variable belongs to. Because every variable is undefined by default if it is not assigned to any variable, a is undefined.

#es5 #es5-vs-es6 #javascript #programming

Basic Overview of Hoisting in JavaScript
1.35 GEEK