JavaScript Hoisting
Hoisting is a concept in JavaScript, not a feature. In other scripting or server side languages, variables or functions must be declared before using it.
In JavaScript, variable and function names can be used before declaring it. The JavaScript compiler moves all the declarations of variables and functions at the top so that there will not be any error. This is called hoisting.
Example: Hoisting
x = 1;
alert('x = ' + x); // display x = 1
var x;The following figure illustrates hoisting.