# Classes: inheritance, private and static members

*JavaScript Developer Study Guide · Objects, Functions, and Classes · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/objects-functions-and-classes/classes-inheritance-private-and-static-members*

How class syntax maps onto constructor functions and prototypes, and how to use extends and super, private # fields, accessors, static members and Error subclasses to meet a requirement, including the ReferenceError, TypeError and SyntaxError traps.

- Certification: Salesforce JavaScript Developer
- Exam section: Objects, Functions, and Classes
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a business requirement, apply fundamentals of class implementation to solve the business requirement.

## What the exam expects

- Explain what a class compiles to (a constructor function plus a prototype) and predict `typeof`, `instanceof` and prototype checks on classes and instances.
- Know the behaviour changes when constructor functions move to classes: TDZ instead of hoisting, `new` required, strict mode, non-enumerable methods.
- Write a subclass with `extends`, call `super()` before `this`, and reuse a parent method with `super.method()`.
- Choose between a `#private` field, a getter with no setter, a public field and a `static` member from an encapsulation or sharing requirement.
- Predict `this` in static factories and detached class methods, and subclass `Error` for a custom error type.
- Key terms: **derived class** (a class declared with `extends`); **private element** (a `#name` field or method readable only inside its class body); **static member** (defined on the class itself, not on instances); **class field** (a property declared in the class body and created on each instance); **accessor** (a `get`/`set` pair that runs code on read or write).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| `typeof` a class | `'function'` | [Classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) |
| Class before declaration | ReferenceError (temporal dead zone) | [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) |
| Class without `new` | TypeError | [Using classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_classes) |
| Class body | Always strict mode | [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) |
| Class methods | On the prototype, shared, non-enumerable | [Method definitions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions) |
| `this` before `super()` | ReferenceError in a derived constructor | [super](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super) |
| Default derived constructor | Passes all arguments to the parent constructor | [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor) |
| `#name` outside the class | Early SyntaxError; script does not run | [Private elements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_elements) |
| Static members | On the class; not reachable through instances; inherited by subclasses | [static](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) |
| Public fields | Own, enumerable properties of each instance | [Public class fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields) |
| `instanceof` | Searches the whole prototype chain | [instanceof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) |
| Error subclass `name` | Inherited as `"Error"` unless set | [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |

## Check yourself

- Why does `console.log(wallet.#balance)` outside the class stop even earlier lines from logging?
- When does a derived constructor throw a ReferenceError?
- Why does `new this()` inside an inherited static factory create a subclass instance?
- What does `typeof` return for a class?
- Which check returns true for an instance of any subclass of `Asset`?

## Sources

- [Using classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_classes)
- [Classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes)
- [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class)
- [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor)
- [extends](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends)
- [super](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super)
- [Private elements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_elements)
- [static](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static)
- [Public class fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields)
- [Method definitions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions)
- [get](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)
- [instanceof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof)
- [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
- [Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
- [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 15 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
