Foundations Flashcards

(36 cards)

1
Q

Object.getPrototypeOf()

A

Returns the object’s prototype property

Parameters:
Takes an object

Returns:
Value associated with the [[Prototype]] property which is all of the built-in prototype methods

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

Object.create()

A

Creates an object

Const obj = Object.create(someObj)

Adds one object to another objects __proto__

In the example above someObj is added as a method to the obj’s prototype chain

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

This. keyword

A

Refers to the object scoped above as the owner of the property that comes after the dot in the variable reference

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

Factory function

A

A function that

  1. Returns an object literal
  2. Is not a constructor function

Example

Function puppyFactory(name, breed) { 
Return {
Name,
Breed
}
}

Const Fido = puppyFactory(“Fido”, “bulldog”)

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

Object creational design pattern

A

Design pattern that instantiates and organizes the object for what it will be used for later

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

Arrow function

A

Syntactically compact alternative to a regular function expression

Ill-suites as methods
Cannot be used as constructor functions

Regular functions:

Function func() {
Return {
Name,
Age
}
}
Function func() {
Return {
Name,
Age
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Constructor functions

A

Ordinary functions invoked with the new operator and return an object instance

First letter is capitalized

Const Jedi = function(level, color) {
Const instance = {level,color}
Return instance
}

Const newInstance = new Jedi(‘Luke’, ‘green’)

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

New keyword

A

Allows the user to create a new object using a constructor function

Const sneaker = new Shoe()

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

Console.dir

A

Console.log but shows all properties attached to an object

This list is interactive which means that it’s possible to see all the nested properties of an object like the .prototype and .__proto__ properties

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

arguments

A

An array-like object that contains all the arguments passed into a function

function func(a) {

Console.log(arguments[0])

}

A

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

.forEach method

A

takes a function as an argument and Runs that function on each element in an array

This method is called on an array

Arr.forEach(function)

———

For (let i = 0: i < arr.length; i++) { 
Copy.push(items[i])
}

items.forEach(function(item) {
Copy.push(item)
}

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

Refactor with arrow function:

Hello = function() {
Return “hello”
}

A

Hello = () => {
Return “hello”
}

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

Arrow function that returns an object

A

Const funcname = (parameters) => ({key: value, key: value})

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

ForEach with arrow function notation

A

forEach.((func, index, arr) => {
Console.log(“hello”)
}

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

Spread operator

A

Refers to name of array in place of its elements

Const numbers = [1,2,3]

Console.log(…numbers)

1,2,3

Behind the scenes it creates a shallow copy of the array

Cannot he used with nested objects or arrays

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

First class functions

A

Returned by another function

Passed in as an argument

Assigned as a variable, method or stored in an array

17
Q

Higher order functions

A

Takes another function as an argument

18
Q

Filter method

A

Const checkAdult = (age) => {
Return age >= 18
}

Const func = () => {
Let adultsNumber = Ages.filter(checkAdult)
Return adultNumber
}

19
Q

Map method

A

Arr.map(function)

Returns an array

Similar to forEach, but map returns something (an array

20
Q

Map method chain

A

Add one method after another separating them with a dot. This causes the methods to be called one after the other

myName = “Scott”

myName.toUpperCase()

SCOTT

myName.toUpperCase().split(‘’)

[S,C,O,T,T]

21
Q

Object.keys() and Object.values()

A

Returns all keys and values respectively as an array

22
Q

Map method with an object

A

Const someVar = Object.keys(petObj).map((key) => {
Return ${key} is a petObj[key]
}

23
Q

Reduce method

A

Accepts a function and a starting value as arguments

Returns a single value

Arr.reduce(callback,initial value)

Accumulator = the value that we end with

Reducer = the action we perform on each value in the iterable object to get the result

Const initialvalue = 0
Const numbers = [5,10,15]

Const reducer = (accumulator, item) => {
Return accumulator + item
}

Const total = numbers.reduce(reducer,initial value)

24
Q

.call method

A

Recontextualizes the ‘this’ keyword to another object.

Call takes an object as an argument and the this redirects itself to refer to the values in that object

Const person = {
fullName: function() {
Return this.firstName + this.lastName
}

25
5 kinds of scope and what they mean (2 of these scope types are subsets of another type of scope)
Global - highest level of scope in the js document and is accessible by all the code Local - scope only to the function in which is occurs. 2 kinds of local scope are functional and block scope Functional - only accessible to the function Block - accessible only within an if, switch condition or any kind of loop Lexical scope - the children of the thing to which the variable is scoped can access it *note - even if the same variables are declared in different scopes, they are not mutually visible
26
Scope of let and var
Let is block scoped - Var is globally scoped ``` Function func1() { Var x = 1 { var x=2 // same variable Console.log(var) // 2 } Console.log(var) // 2 } ``` ``` Function func1() { Let x = 1 { let x=2 // different variable Console.log(let) // 2 } Console.log(let) // 1 } ```
27
When is the return keyword not necessary with arrow notation?
When there is only one expression to be evaluated Eg Const func x => x*5
28
When are the parentheses and first = in an arrow notation function not necessary?
When there is only one parameter Instead of Const func = (x) => {} Use Const func x => {}
29
Object.assign
The Object.assign() method copies all enumerator own properties from one or more source objects to a target object Object.assign(target, source) Target is the object or empty object that the enumable properties from the source are copied to Source is the object(s) from which the own properties are copied The source paramenter can have multiple objects passed in as arguments
30
Can you use a function call as a property name in bracket notation? typeof num === obj Num = () => { return ‘hello’ + ‘there’ num[hello()] = ‘value’
Yes it can! If a function or anything is passed in to the bracket it’s ok that’s it’s not a string as long as it can be evaluated to one
31
How is object syntax shorthand different in ES6?
You can omit the colons and values as long as the name of the value is the desired name of the property Let one = 1 Let two = 2 Const obj = { one, two} //the values of properties one and two are 1 and 2 respectively
32
[[protoype]] What is it?
It’s a property every object contains and it’s value is a reference to another object The value of the prototype is all the built in methods of JS
33
Wrapper object
Methods are the properties of objects Primitive data types (numbers, Boolean, strings, undefined, null, symbols) do not have methods You can call a method on a PDT because a temporary “wrapper object” is created around the PDT while the method executes - when it’s done the wrapper object is destroyed
34
The prototype chain
This is the link between all of the prototype objects When it evaluates if a method is a property of an object, it looks at the properties and if the desired property isn’t there, it looks at the __proto__ property If the property is there it finds it Else it goes to the __proto__ of the first __proto__ and continues until it’s exhausted the chain If the property isn’t on the object it acts accordingly
35
Implicit binding rule
Says that the this keyword references the object the method is called on ``` Const pizza = { Size: 2, GetSize() { Return this.size } ``` The getSize method is called on pizza. This is determined by the IBR. This.size could also be pizza.size
36
What is a call site and why is it important?
The call site is where the this keyword is located The call site determines the context of the use of the this keyword which determines what it binds to