Section 1

Preview this deck

Prototypal Inheritance

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (61)

Section 1

(50 cards)

Prototypal Inheritance

Front

instances inherit directly from other objects. Instances are typically instantiated via factory functions or `Object.create()`. Instances may be composed from many different objects, allowing for easy selective inheritance. -Prototypes: mentions of concatenative inheritance, prototype delegation, functional inheritance, object composition.

Back

First-class objects

Front

Functions -(They have properties and objects) -They can be called and invoked

Back

Array destructuring

Front

You can get some values from a given array and give them any name you want. code: const numbers = [1, 2, 3, 5, 8, 13, 21]; const [x, y, ...rest] = numbers;

Back

Two way data binding

Front

means that UI fields are bound to model data dynamically such that when a UI field changes, the model data changes with it and vice-versa.

Back

hoisting

Front

JavaScript before executing the code actually moves all variables on top

Back

Singleton

Front

Use to restrict an object to just a single instance of that object across application. Remembers the last time you used something and hands back same entity.

Back

There is a utility function that is called in a class method that takes as an argument a callback function to be invoked when the utility function finishes executing. If you want to use the calling class's lexical this reference, how should you declare the callback function? Why?

Front

As an anonymous arrow function: () => { return this.x }. An arrow function in Javascript preserves the lexical context of the scope that created it.

Back

What is the value of the variable result? const valueOne = "2"; const valueTwo = "2"; const result = valueOne / valueTwo;

Front

1

Back

Functional Programming

Front

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data -Pure functions / function purity. -Avoid side-effects. -Simple function composition. -Examples of functional languages: Lisp, ML, Haskell, Erlang, Clojure, Elm, F Sharp, OCaml, etc... -Mention of features that support FP: first-class functions, higher order functions, functions as arguments/values.

Back

Method

Front

a Javascript function that is stored as a property of an object and invoked through that object.

Back

property of the Function object

Front

Allows you to store properties like variables that's scope is specific to that function. For example if you need a counter for that function alone. uniqueInteger.counter = 0; / Here's the function. It returns a different value each time it is called and uses a "static" property of itself to keep track of the last value it returned. / function uniqueInteger(){ // increment and return our "static" variable return uniqueInteger.counter ++; } const i = uniqueInteger(); // 0 const j = uniqueInteger(); // 1 const k = uniqueInteger(); // 2 const l = uniqueInteger(); // 3

Back

Object Literal

Front

An Object assigned to a variable

Back

Function Literal

Front

A function assigned to a variable

Back

Functional Programming (pros vs cons)

Front

PROS -Using the functional paradigm, programmers avoid any shared state or side-effects, which eliminates bugs caused by multiple functions competing for the same resources -functions tend to be radically simplified and easily recomposed for more generally reusable code compared to OOP. -FP also tends to favor declarative and denotational styles, which do not spell out step-by-step instructions for operations, but instead concentrate on what to do, letting the underlying functions take care of the how. CONS -Over exploitation of FP features such as point-free style and large compositions can potentially reduce readability because the resulting code is often more abstractly specified, more terse, and less concrete. -More people are familiar with OO and imperative programming than functional programming, so even common idioms in functional programming can be confusing to new team members.

Back

call()

Front

-First argument is object on which the function must be invoked -Any remaining arguments to call() are the values passed to the function that is invoked.

Back

RegEx

Front

Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects.

Back

var

Front

functionally scoped, global

Back

What does a function return?

Front

Whatever is after "return" or "undefined"

Back

Object destructuring

Front

You can get some values from a given object and give them any name you want. code: const person = { name: 'Coding Sam', age: 28, gender: 'M', address: 'I am not going to tell you xD', phone: '111111111', }; const { name, age, ...rest } = person;

Back

this

Front

refers to the object through which the method is invoked.

Back

How can you create a function that will invoke immediately?

Front

(function() { statements })();

Back

Dynamic binding

Front

process of determining the method to invoke at runtime rather than compile time. JavaScript accomplishes that with this and the prototype chain.

Back

apply()

Front

like the call() method, expect that the arguments can be passed to the function as an ARRAY:

Back

const

Front

is just like let, but immutable.

Back

asynchronous programming

Front

the engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result. When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues. In this way, a single program thread can handle many concurrent operations.

Back

bind()

Front

- returns a bound function that, when executed later, will have the correct context for the this keyword. - can be used when the function needs to be called later whenever it's needed.

Back

How can data be provided to a running generator?

Front

next()

Back

scope

Front

Portion of the code where variable is visible

Back

instanceOf vs TypeOf

Front

Use instance of for objects and arrays and custom types and typeOf for primitive types

Back

microservice architecture

Front

app is made up of lots of smaller, independent applications capable of running in their own memory space and scaling independently from each other across potentially many separate machines. PROS Microservice architectures are typically better organized, since each microservice has a very specific job, and is not concerned with the jobs of other components. Decoupled services are also easier to recompose and reconfigure to serve the purposes of different apps (for example, serving both the web clients and public API). They can also have performance advantages depending on how they're organized because it's possible to isolate hot services and scale them independent of the rest of the app. CONS As you're building a new microservice architecture, you're likely to discover lots of cross-cutting concerns that you did not anticipate at design time.

Back

dynamic object extension

Front

the ability to add to an object after it has been instantiated.

Back

OOP (pros vs cons)

Front

Pros: It's easy to understand the basic concept of objects and easy to interpret the meaning of method calls. OOP tends to use an imperative style rather than a declarative style, which reads like a straight-forward set of instructions for the computer to follow. Cons: OOP Typically depends on shared state. Objects and behaviors are typically tacked together on the same entity, which may be accessed at random by any number of functions with non-deterministic order, which may lead to undesirable behavior such as race conditions.

Back

Attributes of JavaScript Functions

Front

-They have properties and objects -First Class objects - Can be assigned to variables - Can be stored in the properties of objects or the elements of arrays -Can be passed as arguments -Can be assigned properties through the Function object -nested within other functions -lexically rather than dynamically scoped. This means that they run in the scope in which they are defined not the scope in which they are executed.

Back

Closure

Front

combination of a function and the lexical environment within which that function was declared. This environment consists of any local variables that were in-scope at the time the closure was created (its birth scope).

Back

let

Front

a new variable declaration which is block scoped.

Back

What is the correct syntax for declaring an object literal?

Front

const obj = {}

Back

The spread operator

Front

You can expand an array, an object or a string using the spread operator ....

Back

Class Inheritance

Front

instances inherit from classes (like a blueprint — a description of the class), and create sub-class relationships: hierarchical class taxonomies. Instances are typically instantiated via constructor functions with the `new` keyword. Class inheritance may or may not use the `class` keyword from ES6. -Classes: create tight coupling or hierarchies/taxonomies.

Back

Generators

Front

Generators are a special kind of function with the ability to pause themselves, and resume later, allowing other code to run in the meantime. A generator can contain many yield keywords, thus halting itself multiple times, and it's identified by the *function keyword

Back

Which RegExp literal pattern has the global search flag?

Front

const re = /w+\s/g

Back

falsy values

Front

0 -0 NaN undefined null '' //empty string

Back

Template Literals

Front

Template literals are a new syntax to create strings: const aString = `A string` They provide a way to embed expressions into strings, effectively interpolating the values, by using the ${a_variable} syntax:

Back

factory functions

Front

simply constructor functions minus the `new` requirement, global pollution danger and awkward limitations

Back

Where would be the best place to close the file opened by the snippet below? let myFile; try { myFile = fs.openSync('path/to/file', 'a'); fs.appendFileSync(myFile, 'text to add', 'utf8'); } catch (e) { // handle error }

Front

In a finally block

Back

monolithic architecture

Front

app is written as one cohesive unit of code whose components are designed to work together, sharing the same memory space and resources. PROS There can also be performance advantages, since shared-memory access is faster than inter-process communication (IPC). When everything is running through the same app, it's easy to hook up components to those cross-cutting concerns. CONS tightly coupled and entangled as the application evolves, making it difficult to isolate services for purposes such as independent scaling or code maintainability. Monolithic architectures are also much harder to understand, because there may be dependencies, side-effects, and magic which are not obvious when you're looking at a particular service or controller.

Back

Block scope

Front

Back

class SomeClass{} let x = new SomeClass(); What operator would you use to check if x is one of the given class?

Front

The instanceof operator; x is instanceof SomeClass

Back

What happens when the javascript interpreter invokes a function

Front

-It sets the scope to the scope chain that was in effect when the function was defined. -It adds a new object (known as the call object) to the front of the scope chain. -This object is initialized with a property named arguments that refers to the Arguments object for the function. -Next, named parameters of the function are added to the call object. -Any local variables declared in the function are also defined within this object.

Back

favor object composition over class inheritance

Front

means that code reuse should be achieved by assembling smaller units of functionality into new objects instead of inheriting from classes and creating object taxonomies. In other words, use can-do, has-a, or uses-a relationships instead of is-a relationships. Avoid class hierarchies. Avoid brittle base class problem. Avoid tight coupling. Avoid rigid taxonomy (forced is-a relationships that are eventually wrong for new use cases). Avoid the gorilla banana problem ("what you wanted was a banana, what you got was a gorilla holding the banana, and the entire jungle"). Make code more flexible.

Back

How can you import and export multiple named objects using ES6 modules?

Front

Using named exports and a destructuring assignment import: export function foo(x) { ... } export function bar(y) { ... } ... import { foo, bar } from './foo';

Back

Section 2

(11 cards)

In the following code snippet, what is the value of y? let x = { foo: '1', bar: '2' } let y = { ...x, baz: '3' }

Front

{ foo: '1', bar: '2', baz: '3' }

Back

How can you define a class that inherits from another class and uses the parent class's constructor?

Front

class Foo(){ constructor(x){ this.x = x; } } class Bar(){ constructor(x, y){ super(x); this.y = y; } }

Back

Script tags that are loaded in the head tag are generally considered to decrease page performance. Why?

Front

The page parsing pauses until the script is executed.

Back

What is a potential pitfall with using typeof bar === "object" to determine if bar is an object? How can this pitfall be avoided?

Front

Although typeof bar === "object" is a reliable way of checking if bar is an object, the surprising gotcha in JavaScript is that null is also considered an object! As long as one is aware of this, the problem can easily be avoided by also checking if bar is null:

Back

Given the statement let person = 'Alice', the statement person instanceof String is false. What does this mean?

Front

'Alice' is a string primitive, and instanceof checks to see what constructor was used to create the item. The String object constructor must be used to create the string for that expression to be true.

Back

When comparing two strings with the less than or greater than operator, what is the return result? var a = 'a'; var b = 'b'; console.log(a < b);

Front

true

Back

Mediator Pattern

Front

Controls communication between objects

Back

How can data be provided to a running generator?

Front

Pass it as a parameter to the next method call.

Back

What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a function block?

Front

This is an increasingly common practice, employed by many popular JavaScript libraries (jQuery, Node.js, etc.). This technique creates a closure around the entire contents of the file which, perhaps most importantly, creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries.

Back

What is the significance, and what are the benefits, of including 'use strict' at the beginning of a JavaScript source file?

Front

The short and most important answer here is that use strict is a way to voluntarily enforce stricter parsing and error handling on your JavaScript code at runtime. Code errors that would otherwise have been ignored or would have failed silently will now generate errors or throw exceptions. In general, it is a good practice.

Back

How can you instantiate a RegExp object?

Front

Correct - With the constructor: new RegExp('^\d+$'); or as a literal: /^\d+$/

Back