Final Exam Deck #2 Flashcards

1
Q

how does the setTimeout( ) function work? What are its parameters?

A

setTimeout( callback(), msDelay )

It runs the callback function after the indicated delay (ms)

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

What are the parameters of the promise constructor?

A

resolve and reject

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

What is the “then” method and what does it do? What are its parameter(s)?

A

“then” is a method of the Promise class. It takes a callback function as a parameter and runs it if the promise is resolved.

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

What is the “catch” method and what does it do? What are its parameter(s)?

A

“catch” is a method of the Promise class. It takes a callback function as a parameter and runs it if the promise is rejected

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

For the following class:

class Student{

constructor(name, grade){
	this.name = name;
	this.grade = grade;
}

getDetails(){
	return ....
}

static compareGrades(stu1, stu2) {
	....
}

}

Student Shane = new Student(… , …)
Student Cameron = new Student(… , …)

how would you call each of the methods for Shane?

A

a) Shane.getDetails( );

b) Student.compare(Shane, Cameron);

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

Are static methods class based methods or instance based methods?

A

Static methods only pertain to the class itself not an instance of the class

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

True or false:

You can call a static method with:

instanceOfClass.staticMethod( )

A

False:

must be:
ClassName.staticMethod?

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

What does “this” refer to in a static method?

A

The class itself (as opposed to an instance)

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

For a general use of the reduce method:

const somethingNew = array.reduce( (accumulator, element) =>
, defaultThing);

What value gets assigned to “somethingNew” after reduce has gone through each element of the array?

A

The accumulator gets assigned to “somethingNew”

i.e. it becomes whatever the accumulator is at the end.

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

Do arrow functions without parentheses have a return statement?

A

No. The return is implied

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

How is the accumulator value updated each time the callback function runs.

A

The value returned from the callback function becomes the new accumulator.

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

What is wrong with the following code:

if(raining):
console.log(‘its raining’);
else:
console.log(‘not raining’);

A

No colon after “if” and “else” statement

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

When using the reduce() method, do we need to declare a base value after the callback function?

A

Yes

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

Can advanced for loops be used for an object? If so what would it like for nums in a numberArray

A

Yes

for(const num in NumberArray)

Don’t forget the ‘const’ here

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

When creating a private field of a class, what is the code for the getter and setter methods within the constructor?

Ex: for a private field called “password”

A

this.getPassword = function(){
return this.__password__;
}

this.setPassword = function(pass){
this.__password__ = pass;
}

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