OutputNot attempted
Static methods are not on instances
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(new Chameleon().newColor, Chameleon.colorChange('orange'));console.log(freddie.colorChange('orange'));Spaces and quote style don’t matter · write a thrown error as TypeError
Ctrl Enter
Show answer & explanation
The expected output comes from actually running the snippet; opening this shows it next to the explanation.
Static methods live on the class (constructor) itself, not on Chameleon.prototype, so instances can't see them: freddie.colorChange is undefined, and calling it throws TypeError. Inside a static method, this is the class.