This section covers the questions for JavaScript Objects to clear all your concepts.
Question 1
Which is the correct way to create an object in JavaScript?
let obj = Object();
let obj = { key: "value" };
let obj = new Object("key", "value");
let obj = Object.create();
Question 2
How do you access the property of an object using bracket notation?
obj.key
obj["key"]
obj(key)
obj->key
Question 3
Which of the following is a valid way to define a function as a property of an object?
obj.func = function() { ... }
obj.func = () => { ... }
Both
None of the above
Question 4
Which method is used to merge two objects?
Object.assign()
Object.merge()
Object.create()
Object.combine()
Question 5
What is the purpose of the prototype property in JavaScript objects?
To create new properties in an object
To define methods and properties for inheritance
To store the type of the object
To delete existing properties
Question 6
Which of the following creates a deep copy of an object?
JSON.stringify() and JSON.parse()
Object.assign()
Object.create()
Object.freeze()
Question 7
What will the following code log?
const obj = { a: 1 };
obj.b = 2;
console.log(obj);
{ a: 1 }
{ a: 1, b: 2 }
Error
undefined
Question 8
Which of the following is a valid getter in an object?
get name() { return this._name; }
getter name() { return this._name; }
get: function() { return this.name; }
name.get { return this._name; }
Question 9
What will the following code log?
const obj = { a: 1, b: 2 };
delete obj.a;
console.log(obj)
{ b: 2 }
{ a: null, b: 2 }
{ a: undefined, b: 2 }
Error
Question 10
What is the purpose of Object.freeze()?
To prevent new properties from being added
To make the object immutable
To prevent existing properties from being changed
All of the above
There are 10 questions to complete.