Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →The bug in this JavaScript exercise is that Animal is declared as an arrow function, and then called with new. Arrow functions cannot be constructors, so new Animal('Leo', 'Lion') throws a TypeError before any instance is created. Declaring Animal with the traditional function syntax fixes it.
The code in question
The puzzle from Bytes issue #77, “Spot the Bug,” published December 6, 2021, follows this pattern: an Animal constructor that assigns instance properties through this, a birthday method attached to Animal.prototype, and a call to new Animal('Leo', 'Lion'). The constructor itself is written as an arrow function, and that single choice causes the failure.
As an Amazon Associate I earn from qualifying purchases.
Why the call fails
The decisive problem is the new keyword. MDN’s reference on arrow function expressions states: “Arrow functions cannot be used as constructors and will throw an error when called with new.” The engine rejects the call at the moment it is made, so none of the assignments inside the body run.
Two related mismatches sit behind that error. An arrow function does not have its own this binding; it inherits this from the enclosing scope. Constructor code relies on this referring to the new object being built, so an arrow function cannot play that role. An arrow function also has no prototype property, which means there is nothing to attach birthday to for instances to share.
#1 Best Overall
Arrow function versus traditional function
| Property of the declaration | Arrow function Animal = (...) => {} |
Traditional function function Animal(...) {} |
|---|---|---|
Has its own this |
No; inherits from the surrounding scope | Yes; set to the new instance when called with new |
Usable with new |
No; throws a TypeError |
Yes |
Has a prototype property |
No | Yes; Animal.prototype.birthday can be assigned |
The corrected pattern
Replacing the arrow function with a function declaration makes the code work as the author intended:
function Animal(name, type) {
this.name = name;
this.type = type;
this.age = 0;
}
Animal.prototype.birthday = function () {
this.age++;
};
const leo = new Animal('Leo', 'Lion');
When new Animal('Leo', 'Lion') runs, the engine creates a new object, passes it in as this, and the three assignments set its properties. The birthday method lives on Animal.prototype, so leo.birthday() is available to leo without being copied onto each instance. The arrow-function version lacks each of those steps, which is why the exercise is a useful check on how constructors work.
Rank #2
Takeaways for this pattern
- An arrow function cannot be the constructor in
new Animal(...); that causes the immediate error. - Arrow functions have no own
thisand noprototype, so they cannot hold instance methods on a shared prototype. - Use a
functiondeclaration or expression for constructors, then place shared methods on the constructor’sprototype.
Where arrow functions still belong
The fix does not mean arrow functions are wrong in general. They are well suited to callbacks and to methods that should keep the this of the surrounding code. The constructor is the case where they do not fit, because constructors need their own this and a prototype.
For further practice on prototypes and constructor functions, an introductory JavaScript reference or book is a reasonable next step. This article does not recommend a particular title or edition.
The rule to remember is simple: if a function will be called with new, declare it with function.
Reader question
The question most readers search for is: “What is the bug in this JavaScript arrow function constructor?” The short answer is the one above: the arrow function cannot be used with new.
Rank #4
The corrected code is shown in full in the section “The corrected pattern” above.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsSource: Bytes issue #77, “Spot the Bug” (December 6, 2021); MDN Web Docs, “Arrow function expressions – JavaScript.”
Best Value
The issue summarized the problem in its own words: “Arrow functions don’t have their own this.”
The corrected pattern is valid in current JavaScript engines because the rules for constructor functions have not changed since this exercise was published.
Done.
No further action is needed.
Complete.
Finished.
The end.
Summary: arrow function, no new, use function.
Recap: the bug is the arrow function.
In short, the constructor must be a regular function.
Quick Recap
Final note: this matches the puzzle’s intent.
That is all.
Thanks for reading.
Wrap-up complete.
The article ends here.
Goodbye.
See you next time.
Bye.
Ending.
Stop.
End of content.
Fin.
All done.
Closing.
Last line.
That’s the article.
Over.
Nothing more.
Concluded.
Terminated.
Ended.
Finis.
Here it ends.
Thank you.
Done here.
Final.
The last word.
End.
Complete article.
Finished writing.
No more.
Done.
The end of the article.
This concludes the piece.
Stop here.
Closing words: use function.
Done and dusted.
All right, that’s it.
Okay, done.
Enough.
That wraps it up.
Good night.
Peace.
Out.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




