MCQs on Objects and Object-Oriented Basics | JavaScript

Master the essential concepts of objects and object-oriented programming with these multiple-choice questions. This set covers object declaration, properties, the this keyword, and methods—ideal for JavaScript and OOP learners.


MCQs

1. Declaring Objects and Accessing Properties

  1. Which syntax is correct for declaring an object in JavaScript?
    • A) var obj = {name: "John"}
    • B) var obj = "John";
    • C) var obj() = {name: "John"};
    • D) declare obj {name: "John"}
  2. What is the output of console.log(obj.name); if obj = {name: "Alice"};?
    • A) “Alice”
    • B) undefined
    • C) null
    • D) obj.name
  3. How do you access a property with a space in its name?
    • A) obj["first name"]
    • B) obj.first name
    • C) obj.first-name
    • D) obj{first name}
  4. What is the syntax for dynamically accessing a property in an object?
    • A) obj[prop]
    • B) obj.prop
    • C) obj{prop}
    • D) prop(obj)
  5. Which operator is used to access an object’s property?
    • A) +
    • B) -
    • C) .
    • D) &
  6. What would console.log(person["age"]); display if var person = {age: 25};?
    • A) undefined
    • B) 25
    • C) null
    • D) error
  7. Which syntax can be used to access a nested property in an object?
    • A) obj["property"]["nested"]
    • B) obj.property:nested
    • C) obj{property}.{nested}
    • D) obj+property.nested
  8. If let car = {color: "blue"};, which of the following accesses the color property?
    • A) car[color]
    • B) car.color
    • C) car{color}
    • D) car.color[]

2. Adding, Updating, and Deleting Properties

  1. How do you add a new property to an existing object?
    • A) object.property = value;
    • B) object{property} = value;
    • C) object->property = value;
    • D) object(property) = value;
  2. What will be the result of delete person.age; if person = {age: 30};?
    • A) age = null
    • B) The age property is removed
    • C) age becomes undefined
    • D) Error is thrown
  3. How would you update the color property of car to "red" if let car = {color: "blue"};?
    • A) car.color = "red";
    • B) car("color") = "red";
    • C) update car.color = "red";
    • D) color = "red";
  4. Which method deletes a property from an object?
    • A) remove()
    • B) delete
    • C) clear()
    • D) cut()
  5. What does car.model = "Sedan"; do if car initially has no model property?
    • A) Adds model property to car
    • B) Throws an error
    • C) Returns undefined
    • D) Removes model property
  6. What would be the output of console.log(obj.height); after delete obj.height;?
    • A) The deleted value
    • B) null
    • C) undefined
    • D) error
  7. Which is a valid way to add a property with a variable name?
    • A) obj[variable] = value;
    • B) obj(variable) = value;
    • C) obj.variable(value);
    • D) obj->variable = value;
  8. How do you update an existing property value in an object?
    • A) object.property = newValue;
    • B) object->property = newValue;
    • C) object.updateProperty = newValue;
    • D) update.object.property(newValue);

3. this Keyword Basics

  1. In an object, what does this refer to by default?
    • A) The object itself
    • B) Global scope
    • C) The DOM
    • D) Undefined
  2. Which of these best describes the this keyword?
    • A) A variable that stores function arguments
    • B) A pointer to the calling context
    • C) A placeholder for strings
    • D) A syntax to create new variables
  3. How is this used in a method?
    • A) this refers to the global object
    • B) this refers to the calling object
    • C) this is undefined in methods
    • D) this refers to the nested object
  4. What does this.name represent inside an object method?
    • A) Accesses the name property of the object
    • B) Refers to a local variable name
    • C) Refers to a name property in global scope
    • D) Throws an error
  5. What is this bound to in an arrow function?
    • A) The object itself
    • B) Its lexical scope
    • C) this is always undefined
    • D) The window object
  6. Which scenario could make this undefined in an object?
    • A) Calling a method inside the object
    • B) Using strict mode with function expressions
    • C) Declaring a property within an object
    • D) Using this in a nested function without binding
  7. What does this refer to when invoked outside any function or object?
    • A) Global object (e.g., window in browsers)
    • B) The DOM
    • C) An empty object
    • D) null
  8. How do you bind this to a specific object in JavaScript?
    • A) .bind(this)
    • B) .bind(object)
    • C) object.this()
    • D) .apply(object, this)

4. Methods in Objects

  1. Which syntax correctly defines a method within an object?
    • A) method: function() { /* code */ }
    • B) function.method() { /* code */ }
    • C) object.method() = function { /* code */ }
    • D) method() => { /* code */ }
  2. What is the term for a function that is a property of an object?
    • A) Prototype
    • B) Method
    • C) Constructor
    • D) Object literal
  3. How do you call a method named greet in an object person?
    • A) person.greet()
    • B) greet(person)
    • C) person["greet"]
    • D) call person.greet()
  4. What is the return keyword used for in a method?
    • A) To end the function and send a value back
    • B) To create a new object property
    • C) To assign a property
    • D) To delete a method
  5. If let obj = { add: function(x, y) { return x + y; }};, what does obj.add(2, 3); return?
    • A) 5
    • B) 23
    • C) undefined
    • D) Error
  6. What is required for a method to access properties in the same object?
    • A) Use this.propertyName
    • B) Use obj.propertyName
    • C) Use return.propertyName
    • D) Use propertyName.this

Answers

QnoAnswer
1A) var obj = {name: "John"};
2A) “Alice”
3A) obj["first name"]
4A) obj[prop]
5C) .
6B) 25
7A) obj["property"]["nested"]
8B) car.color
9A) object.property = value;
10B) The age property is removed
11A) car.color = "red";
12B) delete
13A) Adds model property to car
14C) undefined
15A) obj[variable] = value;
16A) object.property = newValue;
17A) The object itself
18B) A pointer to the calling context
19B) this refers to the calling object
20A) Accesses the name property of the object
21B) Its lexical scope
22B) Using strict mode with function expressions
23A) Global object (e.g., window in browsers)
24B) .bind(object)
25A) method: function() { /* code */ }
26B) Method
27A) person.greet()
28A) To end the function and send a value back
29A) 5
30A) Use this.propertyName

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top