Class Flashcards

1
Q

commas are needed between class methods

TRUE / FALSE

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
class User {
  constructor(name) { this.name = name; }
  sayHi() { alert(this.name); }
}

alert(typeof User); //

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
class User {
  constructor() {}
}

alert(typeof User);
User(); // returns

A

Error: Class constructor User cannot be invoked without ‘new’

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

A class definition sets enumerable flag to ________ for all methods in the “prototype”.

A

false

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

Class methods are non-enumerable.

True / False

A

true

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

All code inside the class construct is automatically in strict mode.

True / False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
let User = class MyClass {
  sayHi() {
    alert(MyClass); // MyClass is visible only inside the class
  }
};

new User().sayHi(); //

A

works, shows MyClass definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
let User = class MyClass {
  sayHi() {
    alert(MyClass); // MyClass is visible only inside the class
  }
};

alert(MyClass); //

A

error, MyClass not visible outside of the class

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

MyClass is technically a ___________ (the one that we provide as constructor), while methods, getters and settors are written to MyClass.prototype.

A

function

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

The _________ keyword is used in class declarations or class expressions to create a class which is a child of another class.

A

extends

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

The________ keyword is used to access and call functions on an object’s parent.

A

super

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

to call a parent method using super

A

super.methons(…)

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

to call a parent constructor (inside our constructor only) using super

A

super(…)

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

class Animal {

constructor(name) {
this.speed = 0;
this.name = name;
}

run(speed) {
this.speed += speed;
alert(${this.name} runs with speed ${this.speed}.);
}

stop() {
this.speed = 0;
alert(${this.name} stopped.);
}

}

class Rabbit extends Animal {
  hide() {
    alert(`${this.name} hides!`);
  }
  stop() {
    \_\_\_\_\_\_\_\_ // call parent stop
    \_\_\_\_\_\_\_\_\_ // and then hide
  }
}
A

super. stop();

super. stop();

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

Arrow functions have super

TRUE / FALSE

A

Arrow functions have no super

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

We can also assign a method to the class function, not to its “prototype”. Such methods are called _______.

A

static