class syntax sugar over prototypes—constructors, methods, and extends for inheritance.
Basics
class User {
constructor(name) { this.name = name; }
greet() { return `Hi ${this.name}`; }
}
Fields
Public/private fields (#private) and static methods—see MDN for full syntax.
Important interview questions and answers
- Q: Class vs object literal?
A: Classes help shared behavior and instanceof checks. - Q: extends?
A: Child gets parent prototype chain—call super() in constructor.
Self-check
- What does constructor do?
- Why super() in subclass?
Tip: Re-run the playground code for classes-es6-intro and tweak one line before the MCQs.
Interview prep
- class sugar?
Syntactic sugar over prototype inheritance.