You Don't Know JS: Scopes & Closures

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Why does eval() cause a problem related to lexical scope?

Because you can programmatically generate code inside of your authored code, and run the generated code as if it had been there at author time.

What is lexical scope?

A set of rules about how the Engine can look-up a variable and where it will find it. The key characteristic of lexical scope is that it is defined at author time when the code is written assuming you dont cheat with eval() or with()

Chp 5: Scope and Closures What is a Closure?

Closure is when a function is able to remember and access its lexical scope even when that function is executing outside its lexical scope.

Appendix A: Dynamic Scope

Dynamic scope vs Lexical Scope, a good pt to mention is that dynamic scope is actually a near cousin to another mechanism (this) in JS.

What is Lexical Scope?

Lexical Scope is scope that is defined at lexing time. In other words, lexical scope is based on where variables and blocks of scope are authored by you at write time and this is mostly set in stone by the time the lexer processes your code.

What is the key difference between lexical and dynamic scope?

Lexical scope cares where a function was declared, but dynamic scope cares where a function was called from. Also this cares how a func was called which shows how closely the this mechanism is to the idea of dynamic scoping.

Imp pt to rem

No matter where a function is invoked from or even how it is invoked, its lexical scope is only defined by where the function was declared.

Chapter 2: Lexical Scope What is scope?

Scope is defined as the set of rules that govern how the Engine can look up a variable by its identifier name and find it, either in the current Scope or in any of the Nested Scopes its contained within.

What is shadowing?

Scope look up stops once it finds the first match. The same identifier name can be specified at multiple layers of nested scope, which is called shadowing.(the inner identifier shadows the outer identifier).

What is Lexing?

The lexing process examines a string of source code characters and assigns semantic meaning to the tokens as a result of some stateful parsing.

Why does with cause a problem related to lexical scope?

The with statement takes an object, one which has zero or more properties, and treats that object as if it is a wholly separate lexical scope, and thus the objects properties are treated as lexically defined identifiers in that scope.


संबंधित स्टडी सेट्स

Chapter 16 - Commercial and Investment Properties

View Set

APUSH Unit 1 Multiple Choice Part

View Set

Lesson thirteen: MIDDLE BREAD COLONIES

View Set

BLAW Exam 1: Common Law, Statutory Law, and Administrative LawI

View Set

Computer Fundamentals Module 2 - The Web - Quiz

View Set

Binary and Decimal and Hexadecimal Conversions

View Set

Prep U: Chapter 39 Oxygenation and Perfusion

View Set