In JavaScript, the scope goes from outer to inner. This means that variables declared in the outer scope can be accessed in all inner scope, not vice versa. When console.log (sport) was run, it attempted to locate the variable declaration in the favoriteSport function. The external reference point is determined by where your function is lexically positioned. For example, favoriteSport() is Lexically positioned not within function otherSport.

6m read timeFrom blog.bitsrc.io
Post cover image
Table of contents
JavaScript Under The Hood: Advanced Concepts Developers Should KnowThe first thing that happens inside the engineThe Global Execution ContextExecution Context: HoistingExecution context — function invocation and the Call StackExecution Context: Scope ChainJS fascinatingly handles asynchronous tasks!ConclusionBit: Feel the power of component-driven devLearn more
7 Comments

Sort: