This content originally appeared on DEV Community and was authored by Sooraj S
What's the output ?
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor;
return this.newColor;
}
constructor({ newColor = 'green' } = {}) {
this.newColor = newColor;
}
}
const freddie = new Chameleon({ newColor: 'purple' });
console.log(freddie.colorChange('orange'));
- A:
orange
- B:
purple
- C:
green
- D:
TypeError
Answer: D
The colorChange
function is static. Static methods are designed to live only on the constructor in which they are created, and cannot be passed down to any children. Since freddie
is a child, the function is not passed down, and not available on the freddie
instance: a TypeError
is thrown.
This content originally appeared on DEV Community and was authored by Sooraj S
Sooraj S | Sciencx (2021-07-15T07:49:17+00:00) JavaScript question #Day 6. Retrieved from https://www.scien.cx/2021/07/15/javascript-question-day-6/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.