NEW
Font size
WorksheetsJavaScript Object Quiz
Total questions: 30
Worksheet time: 21mins
Which of the following correctly creates an object in JavaScript?
const obj = "key: value";
const obj = [key: value];
const obj = { key: value };
const obj = (key, value);
What is a property in a JavaScript object?
A function inside an object
A key–value pair
An array element
A variable outside an object
What will be the output?
BMW
brand
"car"
undefined
How do you access an object property using a variable key?
person.key
person[key]
person."key"
person->key
Which method returns all keys of an object?
Object.values()
Object.entries()
Object.keys()
Object.list()
In JavaScript, objects are stored as:
Reference types
Primitive types
String literals
Stack-only values
How do you delete a property from an object?
delete obj.key;
remove obj.key;
obj.delete(key);
obj.removeProperty(key);
Output?
true
false
"age"
Error
Which of the following statements is true about objects in JavaScript?
Objects can contain both data and methods.
Objects can only contain numbers.
Objects must be declared using new Object().
Objects cannot be modified.
Output?
HR
undefined
Error
null
What does
Object.assign({}, obj1, obj2) do?
Deletes all properties of obj1 and obj2
Merges obj1 and obj2 into a new object
Compares obj1 and obj2
Copies values only from obj1
Output?
Lina
Sara
Error
undefined
Which method returns both keys and values as pairs?
Object.keys()
Object.entries()
Object.values()
Object.pairs()
What does Object.freeze(obj) do?
Prevents modification of existing properties
Deletes the object
Makes it undefined
Allows adding new properties
Output?
[1, 2]
["a", "b"]
{1, 2}
undefined
Which of these is used to check if a property exists directly on an object (not inherited)?
obj.hasOwnProperty("key")
"key" in obj
Object.keys(obj)
obj.includes("key")
What is the result of spreading objects?
{ a: 1, b: 2 }
{ a: 1 }
Error
undefined
Which of these loops is used to iterate over object keys?
for...in
for...of
forEach()
map()
What does this return?
2
10
20
undefined
What will this print?
3
1
Error
undefined
Output?
5
2
undefined
Error
Output of destructuring:
30
age
undefined
Error
What happens here?
10
20
undefined
Error
What is the output?
false false
true true
true false
false true
What happens in this code?
Alice
Bob
undefined
Error
Predict the output:
["a", 1]
["b", 2]
{a:1}
Error
What’s the output?
6
5
Error
undefined
Tricky merge:
3
2
{b:3}
Error
Nested property access:
Not Available
undefined
Error
0
Output of deep clone with JSON:
Pune
Delhi
undefined
Error
