Search⌘ K
AI Features

Solution Review: Hoisting

Explore how JavaScript hoisting works by examining variable declaration behaviors and output results in sample code. Understand why declarations are lifted while initializations remain in place, helping you grasp this key language concept necessary for interview success.

Question 1: Solution review #

Explanation #

Run the code from the question below:

Javascript (babel-node)
function Add(){
console.log(answer)
var answer = 2
};
Add()

The above code displays undefined as an answer due to the concept of hoisting in Javascript.

Hoisting

...