Javascript Flashcards

1
Q

Explain Closure

A

A closure is the combination of a function bundled with references to its surrounding lexical environment, in short, a closure gives you access to an outer function’s scope from an inner function.

closures control what is and isn’t in scope in a particular function, which variables are shared between sibling functions in the same containing scope.

They are frequently used for data privacy, in event handlers and callbacks, in partial applications, currying and other functional programming patterns.

https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-closure-b2f0d2152b36

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bind

A

the bind method creates a new function that , when called, has its ‘this’ keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

Binding is how you keep the context of ‘this’ within another function.

Binding an object to a function, then referencing the object with the ‘this’ keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

this

A

the value of this is evaluated at runtime, it’s runtime binding.

every javascript function while executing has a reference to its current execution context. ‘this’ is that execution context.

in strict mode ‘this’ is undefined.

function bike() {
  console.log(this.name);
}
var name = "Ninja";
var obj1 = { name: "Pulsar", bike: bike };
var obj2 = { name: "Gixxer", bike: bike };

bike(); // “Ninja”

obj1. bike(); // “Pulsar”
obj2. bike(); // “Gixxer”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

pure function

A

a function that does not mutate its arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

async/await

A

Syntactic Sugar for promises. “Async” lets us write promise based code as if it were synchronous, but without blocking the execution thread. Operates asynchronously via the event loop. Using ‘async’ implies that a promise will be returned.

‘Await’: the operator is used to wait for a Promise. it can be used inside an Async block only. Await makes JS wait until the promise returns a result. It only makes the async function block wait and not the whole program execution.
We cannot use the await keyword inside of regular functions.

Async/Await makes execution sequential

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

class vs prototypal inheritance

A

A class is a blueprint – a description of the object to be created. Classes inherit from classes and create subclass. instances are instantiated with the new keyword, may or may not use the ‘class’ keyword. Class is syntactic sugar for constructor.

Class inheritance is implemented on top of prototypal inheritance, that does not mean it does the same thing. class inheritance uses the prototype chain to wire the child constructor.prototype to parent for delegation. usually the super() constructor is called. These steps form single-ancestor parent/child hierarchies and create the tightest coupling available in OO design.

A Prototype is a working object instance. Objects inherit directly from other objects.

inheritance is fundamentally a code reuse mechanism: A way for different kinds of objects to share code.

Class inheritance creates/parent child object taxonomies as a side effect. Class inheritance has many flaws and causes many problems.

https://medium.com/javascript-scene/master-the-javascript-interview-what-s-the-difference-between-class-prototypal-inheritance-e4cd0a7562e9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

pure function

A

a function that does not mutate its arguments, an example would be redux actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is function composition

A

function composition is the process of combining two or more functions to produce a new function. Composing functions together is like snapping together a series of pipes for our data to flow through.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is functional programming

A

the process of building software by composing pure functions, avoiding shared state, mutable data, and side effects. Functional programming is declarative rather than imperative, and application state flows through pure functions. an example of this would be redux.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

declarative vs imperative

A

imperative is how, declarative is what.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

deserialization

A

Deserialization is the reverse of that process, taking data structured from some format, and rebuilding it into an object. Today, the most popular data format for serializing data is JSON. Before that, it was XML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly