Skip to main content

Posts

Showing posts with the label JavaScript polymorphism

JavaScript OOP Unveiled: Prototypes, Classes & Inheritance

JavaScript OOP Unveiled: Prototypes, Classes & Inheritance

  Object-Oriented Programming (OOP) in JavaScript is based on prototypes rather than classical class-based inheritance. However, with ES6, JavaScript introduced the   class   syntax, making OOP more structured. Here are some commonly asked OOP interview questions in JavaScript. Basic OOP Concepts What are the four principles of Object-Oriented Programming? Encapsulation Abstraction Inheritance Polymorphism How does JavaScript implement OOP? JavaScript uses prototype-based inheritance rather than class-based inheritance. However, ES6 introduced the  class  keyword, which provides syntactic sugar over prototypes. What is a constructor function in JavaScript? A constructor function is a function used to create objects. Example: js function Person ( name, age ) { this . name = name; this . age = age; } let person1 = new Person ( "John" , 30 ); What is the difference between a class and a constructor function? A  class  is syntactic sugar over ...