Final Exam Deck #2 Flashcards
how does the setTimeout( ) function work? What are its parameters?
setTimeout( callback(), msDelay )
It runs the callback function after the indicated delay (ms)
What are the parameters of the promise constructor?
resolve and reject
What is the “then” method and what does it do? What are its parameter(s)?
“then” is a method of the Promise class. It takes a callback function as a parameter and runs it if the promise is resolved.
What is the “catch” method and what does it do? What are its parameter(s)?
“catch” is a method of the Promise class. It takes a callback function as a parameter and runs it if the promise is rejected
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) Shane.getDetails( );
b) Student.compare(Shane, Cameron);
Are static methods class based methods or instance based methods?
Static methods only pertain to the class itself not an instance of the class
True or false:
You can call a static method with:
instanceOfClass.staticMethod( )
False:
must be:
ClassName.staticMethod?
What does “this” refer to in a static method?
The class itself (as opposed to an instance)
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?
The accumulator gets assigned to “somethingNew”
i.e. it becomes whatever the accumulator is at the end.
Do arrow functions without parentheses have a return statement?
No. The return is implied
How is the accumulator value updated each time the callback function runs.
The value returned from the callback function becomes the new accumulator.
What is wrong with the following code:
if(raining):
console.log(‘its raining’);
else:
console.log(‘not raining’);
No colon after “if” and “else” statement
When using the reduce() method, do we need to declare a base value after the callback function?
Yes
Can advanced for loops be used for an object? If so what would it like for nums in a numberArray
Yes
for(const num in NumberArray)
Don’t forget the ‘const’ here
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”
this.getPassword = function(){
return this.__password__;
}
this.setPassword = function(pass){
this.__password__ = pass;
}