TypeScript from JavaScript

Lesson 5 of 6

Classes and Access Modifiers

TypeScript classes add access modifiers on top of JavaScript classes to enforce encapsulation at compile time.

TypeScript

Modifiers

ModifierMeaning
public (default)Accessible from anywhere
privateOnly accessible inside the class itself
readonlyCan be set once (usually in the constructor), never reassigned after

📝 Classes Quiz

Passing score: 70%
  1. 1.What does marking a field `private` do?

  2. 2.A field marked ____ can be set once but never reassigned afterward.

  3. 3.By default, class fields in TypeScript are public.