Encapsulation
Definition
The practice of bundling data and methods that operate on that data within a single unit, while restricting direct access to some of the object's internals. JavaScript uses closures and private class fields (`#`) for encapsulation.
Code Example
Learn More
Related Terms
A function that retains access to variables from its outer (enclosing) scope even after the outer function has returned. Closures are created every time a function is created in JavaScript.
ClassES6 syntactic sugar over JavaScript's prototype-based inheritance. Classes provide a cleaner way to create objects and implement inheritance using extends and super.
PolymorphismThe ability for different classes to respond to the same method call in different ways. In JavaScript, polymorphism is achieved through method overriding in subclasses and duck typing.