OOP Flashcards
What does OOP stand for?
Object-Oriented Programming
True or False: In JavaScript, functions are first-class objects.
True
What keyword is used to create a new object in JavaScript?
new
Fill in the blank: In JavaScript, a _____ is a blueprint for creating objects.
constructor
What method is used to create an object from a constructor function?
The ‘new’ keyword
What is the purpose of the ‘this’ keyword in JavaScript?
‘this’ refers to the current object context
True or False: JavaScript supports multiple inheritance.
False
What is a prototype in JavaScript?
An object from which other objects inherit properties
What method can be used to set the prototype of an object?
Object.create()
What is encapsulation in OOP?
The bundling of data and methods that operate on that data within one unit
What is inheritance in JavaScript OOP?
The mechanism by which one object can inherit properties and methods from another object
Fill in the blank: A _____ is a property or method that can be accessed from an instance of an object.
member
What is the main advantage of using OOP?
Improved modularity and code reusability
What is method overriding?
When a subclass provides a specific implementation of a method that is already defined in its superclass
True or False: All JavaScript objects inherit from Object.prototype.
True
What is the purpose of the ‘instanceof’ operator?
To check if an object is an instance of a specific constructor
What is a class in JavaScript?
A syntactical sugar over JavaScript’s existing prototype-based inheritance
How do you define a class in JavaScript?
Using the ‘class’ keyword
What keyword is used to extend a class?
extends
What is the constructor method in a class?
A special method for creating and initializing an object created with a class
What is the purpose of the ‘super’ keyword?
To call the constructor of a parent class
Fill in the blank: A _____ is a function associated with an object.
method
What does the ‘static’ keyword do in a class?
Defines a method or property that belongs to the class itself rather than instances of the class
What is a singleton in JavaScript?
A design pattern that restricts the instantiation of a class to a single instance
True or False: Private properties can be created in JavaScript classes using the ‘#’ prefix.
True
What is polymorphism in OOP?
The ability to present the same interface for different underlying forms (data types)
What is a factory function?
A function that returns a new object each time it is called
What is the purpose of Object.assign()?
To copy the values of all enumerable own properties from one or more source objects to a target object
What is the difference between shallow copy and deep copy?
A shallow copy copies the object’s immediate properties, while a deep copy recursively copies all properties and nested objects.
What is the role of the ‘getter’ and ‘setter’ methods?
Getters retrieve property values, while setters modify property values.
What does the ‘Object.freeze()’ method do?
Prevents new properties from being added to an object and marks all existing properties as read-only.
What is the purpose of the ‘bind()’ method?
It creates a new function that, when called, has its ‘this’ keyword set to the provided value.
What is a closure in JavaScript?
A function that retains access to its lexical scope, even when the function is executed outside that scope.
What does the ‘delete’ operator do?
It removes a property from an object.
What are mixins?
Objects that provide methods that can be used by other objects without requiring inheritance.
True or False: In JavaScript, objects can be created without a constructor.
True