SHSubjectHub

Encapsulation and Private Attributes (JavaScript)

OOPA-levelLesson packSubscription

About this resource

Understand why we hide an object's internal data, how to declare private fields in modern JavaScript using #, and how to expose them safely using getter methods.

11 slides.

Lesson outline

  1. What's the Problem?
  2. What is Encapsulation?
  3. Private Fields in JavaScript — The `#` Syntax
  4. Getters — Exposing Private Data Safely
  5. BankAccount in JavaScript
  6. UML: Visibility Symbols
  7. JavaScript Private Fields: Common Mistakes
  8. Coding Practice: Private Attributes (BankAccount)
  9. Lesson Summary
Unit bundleUnit 2A · Encapsulation and Private Attributes
Part of: Unit 2A · Encapsulation and Private Attributes: the whole unitEvery resource in the unit in one zip.

More from Unit 2A · Encapsulation and Private Attributes