JavaScript Institute Objects and Classes Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Attempts: 13 | Questions: 20 | Updated: Aug 15, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What is the purpose of the spread operator (...) in object literals?

Explanation

In an object literal, the spread operator (`...`) copies an object’s enumerable own properties into a new object. It is commonly used to make shallow copies or combine objects. If properties have the same name, the value from the later spread or property takes precedence. It does not delete or freeze properties.

Submit
Please wait...
About This Quiz
JavaScript Institute Objects and Classes Quiz - Quiz

Test your understanding of JavaScript objects and classes at the college level. This quiz covers object creation, class syntax, inheritance, encapsulation, and modern ES6+ patterns. Master the fundamentals of object-oriented programming in JavaScript to write scalable, maintainable code.

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Which approach best demonstrates encapsulation in JavaScript classes?

Explanation

Encapsulation bundles an object’s data and behavior while restricting direct access to its internal state. JavaScript private fields, written with a `#` prefix, can be accessed only within the class. Public methods provide controlled ways to read or update that data, helping preserve rules and prevent unintended changes.

Submit

3. What is the purpose of the 'new' keyword when creating an object?

Explanation

The `new` keyword allocates memory for a new object, initializes it, and invokes the object’s constructor to set up its initial state.

Submit

4. In class syntax, what does a static method belong to?

Explanation

A static method is associated with the class itself rather than with individual objects created from it. You call it using the class name, and it generally cannot be called directly on an instance. Static methods are often used for utility operations related to the class.

Submit

5. What does the instanceof operator check?

Explanation

The `instanceof` operator checks whether an object was created from a particular class or its subclass. It returns `true` when the object matches the specified class and `false` otherwise.

Submit

6. Which method checks if a property exists directly on an object (not inherited)?

Explanation

`hasOwnProperty()` returns `true` only when the specified property is defined directly on the object itself. It does not count properties inherited through the object’s prototype chain.

Submit

7. What is polymorphism in the context of JavaScript classes?

Explanation

Polymorphism lets subclasses define methods with the same name as those in a parent class but provide their own behavior. The method that runs depends on the object’s actual class, allowing different objects to respond to the same method call in different ways.

Submit

8. How do you prevent an object from being modified in JavaScript?

Explanation

`Object.freeze()` makes an object immutable by preventing properties from being added, removed, or changed. It is shallow, so nested objects remain modifiable unless they are frozen separately.

Submit

9. What does Object.keys() return?

Explanation

`Object.keys()` returns an array containing an object’s own enumerable property names. It does not return the property values, methods exclusively, or the object’s prototype chain.

Submit

10. In JavaScript, what is the difference between == and === when comparing objects?

Explanation

That answer is inaccurate: when both operands are objects, `==` and `===` compare whether they refer to the same object. The key difference is that `==` may coerce types when comparing an object with a primitive, while `===` never performs type coercion.

Submit

11. What is the primary purpose of a constructor function in JavaScript?

Explanation

A constructor function runs when a new object is created, allowing it to assign initial property values and establish the object’s starting state. Its purpose is not to delete objects, define global variables, or create prototype chains alone.

Submit

12. How do you copy all enumerable properties from one object to another?

Explanation

`Object.assign(target, source)` copies the source object’s own enumerable properties to the target. If a property already exists on the target, its value is overwritten. The method returns the target object.

Submit

13. What does Object.create(null) produce?

Explanation

`Object.create(null)` creates a new object with `null` as its prototype. Unlike ordinary objects, it does not inherit properties or methods from `Object.prototype`, such as `toString` or `hasOwnProperty`. This can be useful when creating a simple dictionary of key-value pairs without inherited properties.

Submit

14. Which method allows you to define a property with a getter and setter?

Explanation

`Object.defineProperty()` lets you add or modify an object property using a property descriptor. The descriptor can include `get` and `set` functions, which run when the property is read or assigned. The other methods create, copy, or freeze objects, but do not define a property with custom getter and setter behavior.

Submit

15. What is the correct way to define a private field in a modern ES2022 class?

Explanation

In ES2022, a private class field is declared with a `#` prefix, such as `#fieldName`. It can be accessed only from within the class body, and attempts to access it from outside the class cause an error. An underscore is only a naming convention, not true privacy.

Submit

16. In a subclass, which keyword calls the parent class constructor?

Explanation

In a subclass, `super()` calls the parent class constructor, allowing it to initialize inherited properties before the subclass performs its own setup.

Submit

17. How do you create a subclass that inherits from a parent class in ES6?

Explanation

In ES6, the `extends` keyword declares that `Child` inherits from `Parent`. This gives `Child` access to the parent class’s methods and properties, and the subclass can add or override behavior. The `class Child extends Parent {}` syntax is the standard way to establish this class inheritance relationship.

Submit

18. What does the 'this' keyword refer to inside a class method?

Explanation

Inside a class method, `this` refers to the object instance on which the method is called. It lets the method access that instance’s properties and other methods, such as `this.name` or `this.calculate()`.

Submit

19. Which statement correctly demonstrates object property access using bracket notation?

Explanation

Bracket notation accesses or assigns an object property using square brackets. The expression inside the brackets can be a variable containing the property name, making this form useful when the property name is determined dynamically. For example, if `propertyName` contains `"color"`, `obj[propertyName] = value` assigns `value` to `obj.color`.

Submit

20. In ES6 class syntax, what keyword is used to define a method that runs when an object is created?

Explanation

In ES6, a class’s `constructor` method runs automatically when a new object is created with the `new` keyword. It is commonly used to initialize the object’s properties.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the purpose of the spread operator (...) in object literals?
Which approach best demonstrates encapsulation in JavaScript classes?
What is the purpose of the 'new' keyword when creating an object?
In class syntax, what does a static method belong to?
What does the instanceof operator check?
Which method checks if a property exists directly on an object (not...
What is polymorphism in the context of JavaScript classes?
How do you prevent an object from being modified in JavaScript?
What does Object.keys() return?
In JavaScript, what is the difference between == and === when...
What is the primary purpose of a constructor function in JavaScript?
How do you copy all enumerable properties from one object to another?
What does Object.create(null) produce?
Which method allows you to define a property with a getter and setter?
What is the correct way to define a private field in a modern ES2022...
In a subclass, which keyword calls the parent class constructor?
How do you create a subclass that inherits from a parent class in ES6?
What does the 'this' keyword refer to inside a class method?
Which statement correctly demonstrates object property access using...
In ES6 class syntax, what keyword is used to define a method that runs...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!