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 important about operator precedence for && and || and ternary?

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

What is the difference between == and ===?

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

How can a statement completion value be seen?

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

What is the use of "!!"?

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

What is the use of a mixin in JS?

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

What is the difference between parsing and coercion?

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

What is the use of ~ operator?

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

What is important about JSON.stringify?

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

What is the difference between "type casting" and "coercion"?

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

1. What is event capturing and bubbling?

2. What is the use of capture and once?

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

What is copied by value and what by reference?

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

What are the 6 primitive data types in JS? 

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 important about operator precedence for && and || and ternary?

|| : the first true value is returned (later values not evaluated)

&&: the last (true) value is returned

both are left-associative

ternary is right-associative

JS Closures

What is the difference between == and ===?

A very common misconception about these two operators is: „== checks values for equality and === checks both values and types for equality.“ While that sounds nice and reasonable, it’s inaccurate. Countless well-respected JavaScript books and blogs have said exactly that, but unfortunately they’re all wrong.

The correct description is: „== allows coercion in the equality comparison and === disallows coercion.“

JS Closures

How can a statement completion value be seen?

Every statement has a completion value. It can be seen when you type the statement such as „var a = 4“ into the console. It will return undefined as completion value. The console returns the last statement’s completion value

JS Closures

What is the use of "!!"?

– it is the double-negator which like the unary + explicitly coerces a value. Namely a boolean.

– same as Boolean(value)

JS Closures

What is the use of a mixin in JS?

behavior is shared through inheritance. However, there are cases when inheritance is not the best solution. Inheritance does not work well for unrelated objects like Bird and Airplane. They can both fly, but a Bird is not a type of Airplane and vice versa.

For unrelated objects, it’s better to use mixins. A mixin allows other objects to use a collection of functions.

let flyMixin = function(obj) {

obj.fly = function() {

console.log(„Flying, wooosh!“);

}

};

The flyMixin takes any object and gives it the fly method.

let bird = {

name: „Donald“,

numLegs: 2

};

let plane = {

model: „777“,

numPassengers: 524

};

flyMixin(bird);

flyMixin(plane);

Here bird and plane are passed into flyMixin, which then assigns the fly function to each object. Now bird and plane can both fly:

bird.fly(); // prints „Flying, wooosh!“

plane.fly(); // prints „Flying, wooosh!“

JS Closures

What is the difference between parsing and coercion?

Parsing should not be seen as a substitute for coercion. These two tasks, while similar, have different purposes. Parse a string as a number when you don’t know/care what other non-numeric characters there may be on the right-hand side. Coerce a string (to a number) when the only acceptable values are numeric and something like „42px“ should be rejected as a number.

Don’t forget that parseInt(..) operates on string values. It makes absolutely no sense to pass a number value to parseInt(..). Nor would it make sense to pass any other type of value, like true, function(){..} or [1,2,3].

If you pass a non-string, the value you pass will automatically be coerced to a string first (see „ToString“ earlier), which would clearly be a kind of hidden implicit coercion. It’s a really bad idea to rely upon such a behavior in your program, so never use parseInt(..) with a non-string value.

JS Closures

What is the use of ~ operator?

bitwise NOT

-(x + 1)

if (str.indexOf(„abc“)!==-1) {
}
// Converts to
if (~str.indexOf(„abc“)) {
}

JS Closures

What is important about JSON.stringify?

Any JSON-safe value can be stringified by JSON.stringify(..). But what is JSON-safe? Any value that can be represented validly in a JSON representation.

It may be easier to consider values that are not JSON-safe. Some examples: undefineds, functions, (ES6+) symbols, and objects with circular references (where property references in an object structure create a never-ending cycle through each other). These are all illegal values for a standard JSON structure, mostly because they aren’t portable to other languages that consume JSON values.

The JSON.stringify(..) utility will automatically omit undefined, function, and symbol values when it comes across them. If such a value is found in an array, that value is replaced by null (so that the array position information isn’t altered)

n optional second argument can be passed to JSON.stringify(..) that is called replacer. This argument can either be an array or a function. It’s used to customize the recursive serialization of an object by providing a filtering mechanism for which properties should and should not be included, in a similar way to how toJSON() can prepare a value for serialization.

A third optional argument can also be passed to JSON.stringify(..), called space, which is used as indentation for prettier human-friendly output.

If you pass an object value to JSON.stringify(..), and that object has a toJSON() method on it, toJSON() is automatically called to (sort of) „coerce“ the value to be JSON-safe before stringification.

JS Closures

What is the difference between "type casting" and "coercion"?

Converting a value from one type to another is often called „type casting,“ when done explicitly, and „coercion“ when done implicitly (forced by the rules of how a value is used).

Another way these terms are often distinguished is as follows: „type casting“ (or „type conversion“) occur in statically typed languages at compile time, while „type coercion“ is a runtime conversion for dynamically typed languages.

However, in JavaScript, most people refer to all these types of conversions as coercion, so the way I prefer to distinguish is to say „implicit coercion“ vs. „explicit coercion.“

JS Closures

1. What is event capturing and bubbling?

2. What is the use of capture and once?

They are forms of event propagation. Event propagation is a mechanism that defines how events propagate or travel through the DOM tree to arrive at its target and what happens to it afterward.

The standard DOM Events describes 3 phases of event propagation:

  1. Capturing phase – the event goes down to the element.
  2. Target phase – the event reached the target element.
  3. Bubbling phase – the event bubbles up from the element.

Default is Bubbling:

When an event happens on an element, it first runs the handlers on it, then on its parent, then all the way up on other ancestors.

The most deeply nested element that caused the event is called a target element, accessible as event.target.

2. Set capture to true to set handler in capturing phase instead of bubbling

Set once to true to allow event only once

JS Closures

What is copied by value and what by reference?

Simple scalar primitives (strings, numbers, etc.) are assigned/passed by value-copy, but compound values (objects, etc.) are assigned/passed by reference-copy. References are not like references/pointers in other languages — they’re never pointed at other variables/references, only at the underlying values.

var a = 2;
var b = a; // `b` is always a copy of the value in `a`
b++;
a; // 2
b; // 3

var c = [1,2,3];
var d = c; // `d` is a reference to the shared `[1,2,3]` value
d.push( 4 );
c; // [1,2,3,4]
d; // [1,2,3,4]

There is no way to use the x reference to change where a is pointing. We could only modify the contents of the shared value that both a and x are pointing to.

To accomplish changing a to have the [4,5,6,7] value contents, you can’t create a new array and assign — you must modify the existing array value:

JS Closures

What are the 6 primitive data types in JS? 
string, number, boolean, undefined, null, symbol

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