Tuesday, December 6, 2016

JavaScript hoisting - Q&A

Question:

Please describe what will be printed out to the screen and why?




Answer

Undefined.
In one word, Hoisting. Hoisting is JavaScript's default behavior of moving all declarations to the top of the current script or the current function. Important to note that JavaScript only hoists declarations, not initializations. Because of Hoisting the code above will actually look like this;

No comments:

Post a Comment