Week 2 Test Flashcards

1
Q

what is the format to write a fat arrow function

A

const functionName = (parameters, go, here) => {
statement1;
statement2;
return <a>;
}</a>

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

If you have a singular parameter and you’re writing a fat arrow function, what is special about that?

A

you don’t have to include the parentheses around the variable

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

if you don’t have any parameters and you’re writing a fat arrow function, what must you do?

A

you still have to include empty parentheses where the parameters would have gone

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

demonstrate the format for writing a function with the fat arrow syntax in a single line of code

A

const functionName = argument => expression;

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

what is the real benefit from writing code in a singular line using the fat arrow function

A

you can do implicit returns

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

when can’t you do an implicit return in a fat arrow function

A

when the fat arrow uses multiple statments

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

if you have empty curly brackets immediately after a fat arrow, what does JavaScript evaluate that as?

A

an empty block

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

what is the default value of an empty block

A

undefined

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

what must you do if you want a single expression fat arrow to return an object?

A

wrap the curly brackets in parentheses

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

what is an object

A

a data structure that stores other data

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

what are the two main differences between objects and arrays

A
  1. arrays are indexed with numbers and objects are index using keys
  2. order is not guaranteed in an object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what are POJOs?

A

plain old javascript objects

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

write a code to assign the value of blue to the key of color to the object of car using bracket notation

A

> car[“color”] = “Blue”;

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

what is the preferred method to determine if a key exists in an object an provide an example of this using looking for the color key in the car object

A

using the in operator
ex.
“color” in car

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

write a code to assign the value of blue to the key of color to the object of car using dot notation

A

car.color = “blue”

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

can you use variables as keys with dot notation or bracket notation?

A

bracket

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

if you try to use a variable as a key with dot notation, what will JS interpret that variable as?

A

it will interpret it as a string, not a variable

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

what is the default value when accessing a key that is not in an object?

A

undefined

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

can we use got notation to iterate through object’s values? If yes how? if no, why not?

A

no because we can only use variables as keys in bracket notation

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

What is a method?

A

a function that belongs to an object; every method is a function, but not every function is a method; it is just a key-value pair where the key is the function name and the value is the function definition

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

what does Object.keys() do?

A

it accepts an object as the argument and returns an array of the keys within that object

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

what does Object.values() do?

A

accepts an object as the argument and returns an array of the values within that Object

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

what is the return value of Object.values

A

an array of values

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

what is the return value of Object.keys

A

an array of keys

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

what does Object.entries() do?

A

accepts an object as the argument and returns an array of the [key, value] pairs within that Object.

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

what data type are keys and values normally in objects?

A

keys are strings, but values can be anything

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

can you increase the value in an object if the data type is a number

A

yes

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

in the car object, where the key of year has a value of 1927; what is the format to increase that year by one and by three?

A

car.year++;

car.year+= 3;

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

what will happen if you try to key into a key that doesn’t exist and assign it a value?

A

it will create a new key and value pair

30
Q

In the car object, there is a nested object named features; within that features object, we want to add the key, windows, and the value, manual. Write the format to do this.

A

car.features.windows = manual

31
Q

write the format to delete the key/value pair (color: “Blue”) from the object car

A

delete car.color

32
Q

can you use a for of loop on an object or an array

A

an array

33
Q

can you use a for in loop on an object or an array

A

both

34
Q

what will you get if you use a for of loop on an object

A

a type error

35
Q

what will a for in loop do to an array?

A

it will grab all of the indexes

36
Q

what will a for in loop do to an object?

A

it will grab all of the keys in the object

37
Q

what are the primitive data types?

A

boolean
null
undefined
number
string

38
Q

what are the reference data types?

A

object
array (which is a type of object)

39
Q

what does it mean for a datatype to be a primitive data type?

A

it is immutable

40
Q

what does it mean for a datatype to be a reference data type?

A

it is mutable

41
Q

what will JS do to a parameter that is declared in a function, but has no argument passed in?

A

it will evaluate that parameter to its default value which is undefined

42
Q

will a function run if parameters are declared, but no arguments passed in?

A

yes

43
Q

what does the rest parameter syntax enable us to do?

A

allows us to capture all of a function’s incoming arguments into an array without specifying each parameter that the function will evaluate

44
Q

which parameter can be the rest parameter?

A

only the last parameter

45
Q

what does the spread operator do?

A

allows you to break down a data type into the elements that make it up and spread the values of that type where elements are expected

46
Q

what can the spread operator do for iterable data types like strings and arrays in specific?

A

spread the elements of that type where arguments are expected

47
Q

write a code to take an array named numArray which is [1, 2, 3] and spread it into a new array named moreNums and add the numbers 4, 5, 6. What is the new expected outcome from printing moreNums?

A

let moreNums = […numArray, 4, 5, 6];

moreNums = [1, 2, 3, 4, 5, 6]

48
Q

can we use the spread operator on objects?

A

yes

49
Q

can objects be used as arguments spread into the function?

A

no

50
Q

what is the difference between the rest parameter and the spread operator syntax?

A

spread expands a data type into its elements

rest collects multiple elements and condenses them into a single data type

51
Q

what does destructuring allow us to do?

A

extract parts of an array or object into distinct variables

52
Q

what is aliased object destructuring

A

destucturing when the variable we are creating
doesn’t have the same name as our object keys

53
Q

what does a foreach loop do?

A

touches every element in an array to access or modify it in some way

54
Q

what does a map loop do?

A

convert each element to something else and store it in a new array

55
Q

what does a filter loop do?

A

create a new array which is a subset of the original including only those items that meet a certain condition

56
Q

what does the forWach loop take as a parameter?

A

a function

57
Q

how does the forEach loop work

A

it calls a function on every element in the array. it sends the element of the array as the first parameter to the function and the index as the second parameter if needed

58
Q

what is the difference between the foreach looping method and the map?

A

map expects a returned value for every element put into a new array

59
Q

what does the map looping method taje as its parameter?

A

the element from the array and the index of the element if necessary

60
Q

what do you put inside of the function that is the parameter to the filter loop

A

the condition that you would have been checking for in the conditional statment

61
Q

what does the array reduce method do?

A

takes an array of elements or numbers and reduces them into a single value

62
Q

what are the parameters of the array reduce method

A

ca callback function and an initialvalue which is optional but recommended

63
Q

what are the four arguments that the calllback function passed to the reduce method can take?

A

accumulator
currentValue
index (optional)
array (optional)

64
Q

what is the accumulator and the currentValue the first time that the reduce invokes the callback function when there is an initial Value provided?

A

the accumulator is the initialValue and the currentValue is the is the first element

65
Q

what is the accumulator and the currentValue the first time that the reduce invokes the callback function when there is not an initial Value provided?

A

the accumulator is the array’s first element and the currentValue is the array’s second element

66
Q

what is the problem with trying to call the reduce method on an empty array with no initial value

A

you will get a typeError because JS will evaluate the initialValue to undefined

67
Q

what is the return value of an array that has the reduce method applied to it?

A

the return value of the accumulator

68
Q

make a shallow copy of the array1 array with copy as the variable

A

let copy = […array1]

69
Q

can you spread an object into an array? What will the result of this action be?

A

no; you will get a type error

70
Q

can you spread an array into an object? What will the result of this action be?

A

yes, it will use the index position as the key and the value as the value