oh well I was quite surprised to know this feature of javascript called Hoisting and I am sure not many knew this
so what is javascript hoisting ?
Example:-1 x = 5; // Assign 5 to x elem = document.getElementById("demo"); // Find an element elem.innerHTML = x; // Display x in the element var x; // Declare x so what is wrong with above code ? wait !!
In JavaScript, a variable can be declared after it has been used.
In other words; a variable can be used before it has been declared.
Advertisements