wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

JavaScript Object Quiz

Total questions: 30

Worksheet time: 21mins

Name
Class
Date
1.

Which of the following correctly creates an object in JavaScript?

a)

const obj = "key: value";

b)

const obj = [key: value];

c)

const obj = { key: value };

d)

const obj = (key, value);

2.

What is a property in a JavaScript object?

a)

A function inside an object

b)

A key–value pair

c)

An array element

d)

A variable outside an object

3.

What will be the output?

a)

BMW

b)

brand

c)

"car"

d)

undefined

4.

How do you access an object property using a variable key?

a)

person.key

b)

person[key]

c)

person."key"

d)

person->key

5.

Which method returns all keys of an object?

a)

Object.values()

b)

Object.entries()

c)

Object.keys()

d)

Object.list()

6.

In JavaScript, objects are stored as:

a)

Reference types

b)

Primitive types

c)

String literals

d)

Stack-only values

7.

How do you delete a property from an object?

a)

delete obj.key;

b)

remove obj.key;

c)

obj.delete(key);

d)

obj.removeProperty(key);

8.

Output?

a)

true

b)

false

c)

"age"

d)

Error

9.

Which of the following statements is true about objects in JavaScript?

a)

Objects can contain both data and methods.

b)

Objects can only contain numbers.

c)

Objects must be declared using new Object().

d)

Objects cannot be modified.

10.

Output?

a)

HR

b)

undefined

c)

Error

d)

null

11.

What does

Object.assign({}, obj1, obj2) do?

a)

Deletes all properties of obj1 and obj2

b)

Merges obj1 and obj2 into a new object

c)

Compares obj1 and obj2

d)

Copies values only from obj1

12.

Output?

a)

Lina

b)

Sara

c)

Error

d)

undefined

13.

Which method returns both keys and values as pairs?

a)

Object.keys()

b)

Object.entries()

c)

Object.values()

d)

Object.pairs()

14.

What does Object.freeze(obj) do?

a)

Prevents modification of existing properties

b)

Deletes the object

c)

Makes it undefined

d)

Allows adding new properties

15.

Output?

a)

[1, 2]

b)

["a", "b"]

c)

{1, 2}

d)

undefined

16.

Which of these is used to check if a property exists directly on an object (not inherited)?

a)

obj.hasOwnProperty("key")

b)

"key" in obj

c)

Object.keys(obj)

d)

obj.includes("key")

17.

What is the result of spreading objects?

a)

{ a: 1, b: 2 }

b)

{ a: 1 }

c)

Error

d)

undefined

18.

Which of these loops is used to iterate over object keys?

a)

for...in

b)

for...of

c)

forEach()

d)

map()

19.

What does this return?

a)

2

b)

10

c)

20

d)

undefined

20.

What will this print?

a)

3

b)

1

c)

Error

d)

undefined

21.

Output?

a)

5

b)

2

c)

undefined

d)

Error

22.

Output of destructuring:

a)

30

b)

age

c)

undefined

d)

Error

23.

What happens here?

a)

10

b)

20

c)

undefined

d)

Error

24.

What is the output?

a)

false false

b)

true true

c)

true false

d)

false true

25.

What happens in this code?

a)

Alice

b)

Bob

c)

undefined

d)

Error

26.

Predict the output:

a)

["a", 1]

b)

["b", 2]

c)

{a:1}

d)

Error

27.

What’s the output?

a)

6

b)

5

c)

Error

d)

undefined

28.

Tricky merge:

a)

3

b)

2

c)

{b:3}

d)

Error

29.

Nested property access:

a)

Not Available

b)

undefined

c)

Error

d)

0

30.

Output of deep clone with JSON:

a)

Pune

b)

Delhi

c)

undefined

d)

Error