JS Closures an der LMU München

Karteikarten und Zusammenfassungen für 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 is a closure? 

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

What is the use of closures? 

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

What is the use of bind()? 

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

What is hoisting?

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

What happens when you assign a variable that has not yet been declared?

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

What is the return value of: typeof [1,2,3] === typeof {val: 'a', val: 'b', val: 'c'};

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

What is Polyfilling?

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

What is Transpiling?

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

What gives a program state?

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

In a traditional compiled-language process, what is the correct order of the three main steps a program will undergo before executing?

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

What is the responsibility of Scope?

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

What happens during variable assignment? 

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 is a closure? 

It is function + lexical environment


In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is called, at function creation time.

Closure is when a function can remember and access its lexical scope even when it's invoked outside its lexical scope. (e.g. when it is passed around as a value to a variable).


The inner function will have access to the variables in the outer function scope, even after the outer function has returned.


var add = (function () {

  var counter = 0;

  return function () {counter += 1; return counter}

})();


add();

add();

add();


// the counter is now 3

JS Closures

What is the use of closures? 
1. It can be used to make global variables local/private to a function. The Closure then has the function of getter and setter.

2. When leaving out the function, you can define a singelton pattern where the variable is only declared once. 


JS Closures

What is the use of bind()? 
The bind() method creates a new function from an existing function, change the function's this context and provides any arguments you want the new function to be called with

e.g use bind() when a function belongs to an object

var module = {
x: 42,
getX: function() {
return this.x;
}
}

var unboundGetX = module.getX;
console.log(unboundGetX()); // The function gets invoked at the global scope
// expected output: undefined

var boundGetX = unboundGetX.bind(module);
console.log(boundGetX());
// expected output: 42

JS Closures

What is hoisting?

Basically, when Javascript compiles all of your code, all variable declarations using var are hoisted/lifted to the top of their functional/local scope (if declared inside a function) or to the top of their global scope (if declared outside of a function) regardless of where the actual declaration has been made. This is what we mean by “hoisting”.

Function declarations are also hoisted, but these go to the very top, so will sit above all of the variable declarations.


However, a key thing to note is that the only thing that gets moved to the top is the variable declarations , not the actual value given to the variable. (so it returns undefined)


what we have to remember though is that the concept of hoisting is not a literal process (ie, the declarations themselves do not move to the top of the file — it is simply a process of the JavaScript compiler reading them first in order to create space in memory for them).


All identifiers are registered to their respective scopes during compile time. Moreover, every identifier is created at the beginning of the scope it belongs to, every time that scope is entered. The term for registering a variable at the top of its enclosing scope, even though its declaration may appear further down in the scope, is called hoisting.


let and const will throw reference errors. This is because although let and const are hoisted, they are not initialised until the code executes the initialising line. The time between a let or const being hoisted and initialised is commonly know as the temporal dead zone.

JS Closures

What happens when you assign a variable that has not yet been declared?
If you try to set a variable that hasn't been declared, you'll either end up creating a variable in the top-level global scope (bad!) or getting an error, depending on "strict mode" (see "Strict Mode").

JS Closures

What is the return value of: typeof [1,2,3] === typeof {val: 'a', val: 'b', val: 'c'};
Arrays are special objects, so the typeof of both expressions are objects and the return value is true. Run both expressions in your console to see that the return value of typeof [1,2,3] and typeof {1, 2, 3} is object.

JS Closures

What is Polyfilling?
The word "polyfill" is an invented term used to refer to taking the definition of a newer feature and producing a piece of code that's equivalent to the behavior, but is able to run in older JS environments. For example, ES6 defines a utility called Number.isNaN(..) to provide an accurate non-buggy check for NaN values, deprecating the original isNaN(..) utility. But it's easy to polyfill that utility so that you can start using it in your code regardless of whether the end user is in an ES6 browser or not.

If the forwards-compatibility issue is not related to new syntax, but rather to a missing API method that was only recently added, the most common solution is to provide a definition for that missing API method that stands in and acts as if the older environment had already had it natively defined. This pattern is called a polyfill (aka "shim").

JS Closures

What is Transpiling?
Transpiling is using a tool that converts your newer code into older code equivalents. The term combines the terms for transforming + compiling. Essentially, your source code is authored in the new syntax form, but what you deploy to the browser is the transpiled code in old syntax form. You typically insert the transpiler into your build process, similar to your code linter or your minifier.

JS Closures

What gives a program state?
A program is described as stateful if it is designed to remember preceding events or user interactions. The remembered information is called the state. Without state, a program could perform some tasks, but they would be extremely limited in functionality.

JS Closures

In a traditional compiled-language process, what is the correct order of the three main steps a program will undergo before executing?
Tokenizing/Lexing is the process of breaking up a string of characters into meaningful chunks called tokens. Parsing is the act of taking a stream of tokens and turning it into a tree (AST) of nested elements which represent the structure of the program. Code-Generation is the process of taking the tree and turning it into executable code.

JS Closures

What is the responsibility of Scope?
The Scope is responsible for maintaing a look-up list of all declared identifiers and enforcing a strict set of rules as to how these are accessible to currently executing code.

JS Closures

What happens during variable assignment? 
Two distinct actions are taken for a variable assignment: First, Compiler declares a variable (if not previously declared in the current scope), and second, when executing, the Engine looks up the variable in Scope and assigns to it, if found.

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 JS Closures 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