hey guys,
I have finished es6 course, and moved to on to do regex.
I am excited, but wanted to check some of my new learned knowledge on a random quiz I have found online, got some questions wrong want some help on them if possible
What would be the constructor of roger in the example below?
class Animal {
constructor(noise) {
this.noise = noise
}
speak() {
console.log(this.noise)
}
}
class Dog extends Animal {
constructor(size) {
super('bark!')
this.size = size
}
}
const roger = new Dog('large')
the lessons haven’t covered some of the stuff here so I briefly googled,
anyway the answer to the question is Dog , may anyone explain why not Animal? since it is the parent class. and dog uses extends
2nd question
Select the value of obj[123]
const obj = {
}
the choices were undefined or ‘party!’
answer is the latter , how come is ‘party!’? maybe the question is missing something?
Hi, I don’t know much about classes, so I can’t help you with the first one. However, as you suspected, there is no way that second question can be right. If you don’t believe me, could you provide the link to the quiz so we can both check if I was right? Anyways, obviously, if you’re learning about classes, you already know this. But to reference a value in an object, it has to be defined. Since the constant has nothing defined within the object, obj[123] = undefined.
Tldr: Can’t help you with that first question, but the second one is wrong.