To understand function hoisting, let us start by considering the code listed below:
console.log(foo);
var foo = 9;
What should the output be?
In any other programming language, the output here would be a reference error. However, in JavaScript you will…