Mark As Completed Discussion

One Pager Cheat Sheet

  • We can observe that the getMoreBeers() function overwrites the numOfBeers variable, therefore when it is logged 25 will be printed out, which can be explained by scope.
  • Executing this code will print the output.
  • The order of the console log statements is determined by how the call stack works, with the getMoreBeers() function pushing the original statement onto the stack and executing first.
  • A call stack is a data structure that allows a program to keep track of function calls using the stack (first in, last out) data structure.
  • The variable is returned as "undefined" in the log despite being clearly defined above the function.
  • We should let/const and keep track of variable declarations to avoid unexpected results due to hoisting.
  • The declarations of variables with the var keyword in JavaScript are hoisted, but not the initializations.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

That's all we've got! Let's move on to the next tutorial.

If you had any problems with this tutorial, check out the main forum thread here.