public, private and protected
private limits access to the class, protected to subclasses. They are checked by the compiler, #name is truly private at runtime.
Example
class A {
private secret = 1;
#real = 2;
reveal() { return this.secret + this.#real; }
}
console.log(new A().reveal());Result
3
Exercise
Class only.
secret = 1Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.