Since JavaScript is a dynamic language, it supports polymorphism. Polymorphism can be understood as the ability of an object to be different at different times. For example, a shape can be a square, a rectangle, or a circle.
This feature is also supported in JavaScript. It means protecting parts of code from external use. It protects part of the code that does not concern the end user but is important for running an application, such as in an application that stores passwords. Users don't have to know how their passwords are encrypted. Hence, this code is encapsulated.
In JavaScript, inheritance can be used to derive properties of parent objects to their child objects and have some unique attributes for themselves as well. For example, a square and a triangle may inherit their stroke or fill from a shape
object and, at the same time, have a number of vertices unique to themselves.