JavaScript scope

Lukas Polak
1 min readSep 4, 2020

--

The scope is at the base closure and manages the variables’ availability and defines the idea of a global and local variable. In other words, the scope is an encapsulation mechanism for code blocks, functions, and modules. ES6 and CommonJS modules also create a scope, unless the variable is explicitly exported. Scopes can be nested, and we can use the terms “outer” and “inner” scope for nesting. The inner scope can access the variable of its outer scope. The variables declared inside the global scope are called “global” variables and can be accessed from any scope. Browser supplies window and document global variables. Code block does not create scope for var variables; only the function body does.

Static scoping (lexical scoping) — means that the “inner” scope can access the variable of its outer scope. The variables’ accessibility is determined statically by the position of the variables within the nested function scope and consists of outer scopes.

Originally published at https://dev.to on September 4, 2020.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response