JS Closures an der LMU München

Arrow Arrow

Komplett kostenfrei

studysmarter schule studium
d

4.5 /5

studysmarter schule studium
d

4.8 /5

studysmarter schule studium
d

4.5 /5

studysmarter schule studium
d

4.8 /5

Lerne jetzt mit Karteikarten und Zusammenfassungen für den Kurs JS Closures an der LMU München.

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What are arrow functions? 

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What does 'shadowing' mean (in the context of scope)? 

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

When is redeclaration of variables possible?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What is the connection between the global object and a global variable?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What is special about function expressions concerning the scope? 

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What is special about shadowing for var and let? 

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What is an immediately invoked function expression (IIFE)? 

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What is the difference between Syntax Errors and Type Errors?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

When a variable is declared at the top-level in a ES-module, is it a global variable?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

What are web workers?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

At what point in time is the scope determined? Compile time or run time?

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

Does the Engine need a run-time lookup to see which variable has which scope? 

Kommilitonen im Kurs JS Closures an der LMU München. erstellen und teilen Zusammenfassungen, Karteikarten, Lernpläne und andere Lernmaterialien mit der intelligenten StudySmarter Lernapp. Jetzt mitmachen!

Jetzt mitmachen!

Flashcard Flashcard

Beispielhafte Karteikarten für JS Closures an der LMU München auf StudySmarter:

JS Closures

What are arrow functions? 

They are anonymous function expressions (there are no declared arrow functions and none with name identifiers)

Arrow functions do not have their own this value. The value of this inside an arrow function is always inherited from the enclosing scope (This means that the this binding is not dynamic like for normal functions, but determined by lexical scope)

arrow functions automatically bind the value of this for all the code inside a function

In addition to lexical this, arrow functions also have lexical arguments — they don’t have their own arguments array but instead inherit from their parent — as well as lexical super and new.target

JS Closures

What does 'shadowing' mean (in the context of scope)? 

It means that when you have two identical lexical names (of variables), the name of the inner scope will ’shadow‘ /hide the one from the outer scope so that the one from the outer scope will not be considered.

the only way to access a shadowed variable from inside the scope where the shadowing variable is present, is to take the outer variable through the global object. This shoud not be done though.. and also this only works for variables in global scope.

a global object property can be shadowed by a global variable

A variable in outer scope can always be copied into inner scope though. 

JS Closures

When is redeclaration of variables possible?

 the only way to „re-declare“ a variable is to use var for all (two or more) of its declarations. if let or const are used at least once, it throws a Syntax Error, since this feature was disallowed with ES6.

All the rules of scope (including „re-declaration“ of let-created variables) are applied per scope instance. In other words, each time a scope is entered during execution, everything resets.

Each loop iteration is its own new scope instance, and within each scope instance, value is only being declared once. So there’s no attempted „re-declaration“, and thus no error.

If a var variable is declared in a loop, var gets attached to the global scope

 const can’t be used with the classic for-loop form because of the re-assignment

JS Closures

What is the connection between the global object and a global variable?

The window.studentName is a mirror of the global studentName variable, not a snapshot copy. Changes to one are reflected in the other, in either direction. Think of window.studentName as a getter/setter that accesses the actual studentName variable. As a matter of fact, you can even add a variable to the global scope by creating/setting a property on the global object (window).

This little „trick“ only works for accessing a global scope variable (that was declared with var or function). Other forms of global scope variable declarations do not create mirrored global object properties

JS Closures

What is special about function expressions concerning the scope? 

If the function expression has a name identifier, the name identifier will be created in the function scope and not in the outer scope like the variable name of that function

JS Closures

What is special about shadowing for var and let? 

Let can shadow var, but var can not shadow let. Var can also not shadow a predefined global property (e.g. name), but let could.

JS Closures

What is an immediately invoked function expression (IIFE)? 

function expression that’s immediately invoked

(function () {
    statements
})();

IIFEs are useful when we want to create a scope to hide variables/functions. Since they are expressions, they can be used in any place in a JS program where an expression is allowed. IIFEs can be named, as with hideTheCache(), or (much more commonly!) unnamed/anonymous. When you name it, it cn be easier debugged since it appears in the call stack. And they can be standalone or part of another statement. 

For example, a return statement in some piece of code would change its meaning if then wrapped in an IIFE, because now the return would refer to the IIFE’s function. Non-arrow function IIFEs also change the binding of a this keyword. And statements like break and continue won’t operate across an IIFE function boundary to control an outer loop or block.

So, if the code you need to wrap a scope around has returnthisbreak, or continue in it, an IIFE is probably not the best approach. In that case, you might look to create the scope with a block instead of a function.

JS Closures

What is the difference between Syntax Errors and Type Errors?

The subtle distinction here is actually pretty important, but unfortunately far too easy to miss. Syntax Errors represent faults in the program that stop it from even starting execution. Type Errors represent faults that arise during program execution.

JS Closures

When a variable is declared at the top-level in a ES-module, is it a global variable?

No, it is more module-global (although it is possible to add global variables). This has the advantage of not being super dependent on the global scope.

JS Closures

What are web workers?

Web Workers are a web platform extension for typical browser-JS behavior, which allows a JS file to run in a completely separate thread (operating system wise) from the thread that’s running the main browser-hosted JS.

Since these web worker programs run on a separate thread, they’re restricted in their communications with the main application thread, to avoid/control race conditions and other complications. Web worker code does not have access to the DOM, for example. Some web APIs are however made available to the worker, such as navigator.

Since a web worker is treated as a wholly separate program, it does not share the global scope with the main JS program. However, the browser’s JS engine is still running the code, so we can expect similar purity of its global scope behavior. But there is no DOM access, so the window alias for the global scope doesn’t exist.

In a web worker, a global object reference is typically made with self.

So this also shows that the global object is different depending on the JS environment. For a browser, it’s the window, for a web worker, it’s self.

JS Closures

At what point in time is the scope determined? Compile time or run time?

Of course at compile time since the scope cannot be altered during run time. It is determined by the position of the initializers/variables (in functions, blocks)

JS Closures

Does the Engine need a run-time lookup to see which variable has which scope? 

No, this information is already stored in the entry of a variable in the AST. This makes the run-time process more efficient which is a huge benefit of lexical scope.

There is although a case where run-time deferred lookup is required namely when the program is split in multiple modules and needs these parts to compile and run before any scope is available to certain parts. 

Melde dich jetzt kostenfrei an um alle Karteikarten und Zusammenfassungen für JS Closures an der LMU München zu sehen

Singup Image Singup Image
Wave

Andere Kurse aus deinem Studiengang

Für deinen Studiengang an der LMU München gibt es bereits viele Kurse auf StudySmarter, denen du beitreten kannst. Karteikarten, Zusammenfassungen und vieles mehr warten auf dich.

Zurück zur LMU München Übersichtsseite

Was ist StudySmarter?

Was ist StudySmarter?

StudySmarter ist eine intelligente Lernapp für Studenten. Mit StudySmarter kannst du dir effizient und spielerisch Karteikarten, Zusammenfassungen, Mind-Maps, Lernpläne und mehr erstellen. Erstelle deine eigenen Karteikarten z.B. für JS Closures an der LMU München oder greife auf tausende Lernmaterialien deiner Kommilitonen zu. Egal, ob an deiner Uni oder an anderen Universitäten. Hunderttausende Studierende bereiten sich mit StudySmarter effizient auf ihre Klausuren vor. Erhältlich auf Web, Android & iOS. Komplett kostenfrei. Keine Haken.

Awards

Bestes EdTech Startup in Deutschland

Awards
Awards

European Youth Award in Smart Learning

Awards
Awards

Bestes EdTech Startup in Europa

Awards
Awards

Bestes EdTech Startup in Deutschland

Awards
Awards

European Youth Award in Smart Learning

Awards
Awards

Bestes EdTech Startup in Europa

Awards

So funktioniert's

Top-Image

Individueller Lernplan

StudySmarter erstellt dir einen individuellen Lernplan, abgestimmt auf deinen Lerntyp.

Top-Image

Erstelle Karteikarten

Erstelle dir Karteikarten mit Hilfe der Screenshot-, und Markierfunktion, direkt aus deinen Inhalten.

Top-Image

Erstelle Zusammenfassungen

Markiere die wichtigsten Passagen in deinen Dokumenten und bekomme deine Zusammenfassung.

Top-Image

Lerne alleine oder im Team

StudySmarter findet deine Lerngruppe automatisch. Teile deine Lerninhalte mit Freunden und erhalte Antworten auf deine Fragen.

Top-Image

Statistiken und Feedback

Behalte immer den Überblick über deinen Lernfortschritt. StudySmarter führt dich zur Traumnote.

1

Lernplan

2

Karteikarten

3

Zusammenfassungen

4

Teamwork

5

Feedback