This quiz focuses on fundamental JavaScript data structures: Arrays, Objects, and their operations. You’ll explore key methods, access techniques, and manipulation strategies to strengthen your understanding.
Question 1.
Which of the following methods adds an element to the end of an array?
A.
pop()
B.
push()
C.
unshift()
D.
shift()
Your Response:
-
Explanation: The push() method adds one or more elements to the end of an array and returns the new length.
Question 2.
How can you access the value 3 from the following array?
A.
arr[2][0]
B.
arr[2][1]
C.
arr[1][0]
D.
arr[0][2]
Your Response:
-
Explanation: arr[2] gives [3, 4], and [3, 4][0] gives 3.
Question 3.
What does Object.keys() return?
A.
An array of object keys
B.
An array of object values
C.
A string of keys
D.
undefined
Your Response:
-
Explanation: Object.keys() returns an array of strings, where each string corresponds to a property name of the object.
Question 4.
What is the output of arr.length after this code?
A.
3
B.
5
C.
6
D.
undefined
Your Response:
-
Explanation: The length of the array is determined by the highest index + 1. Setting arr[5] = 6 adds empty slots and updates the length to 6.
Question 5.
What does arr.slice(1, 3) return for arr = [10, 20, 30, 40]?
A.
[10, 20]
B.
[20, 30]
C.
[30,40]
D.
[20, 30, 40]
Your Response:
-
Explanation: slice(start, end) extracts elements starting from start index up to (but not including) end.
Question 6.
Which of these is true about objects in JavaScript?
A.
Keys can only be strings.
B.
Values must be primitives.
C.
They are unordered collections of key-value pairs.
D.
They cannot have nested structures.
Your Response:
-
Explanation: Objects store key-value pairs, and their keys are unordered. Keys can be strings or symbols, and values can be any type.
Question 7.
How can you combine two arrays, arr1 and arr2, without modifying them?
A.
arr1.concat(arr2)
B.
arr1.push(arr2)
C.
arr1.join(arr2)
D.
arr1.splice(arr2)
Your Response:
-
Explanation: The concat() method combines two arrays into a new array without changing the original arrays.
Question 8.
What does delete obj.key do?
A.
Removes the key-value pair from the object.
B.
Sets the value to null.
C.
Sets the value to undefined.
D.
Throws an error.
Your Response:
-
Explanation: The delete operator removes a property from an object entirely.
Question 9.
Which method converts an array into a string with a specified separator?
A.
join()
B.
toString()
C.
split()
D.
concat()
Your Response:
-
Explanation: The join() method joins all elements of an array into a string, separated by the specified separator.
Question 10.
What will below code do?
A.
Add a property key1 with value 'value' and key2 with 'value2'.
B.
Add a property key1 with value 'value' but throw an error for key2.
C.
Throw an error because objects are immutable.
D.
None of the above.
Your Response:
-
Explanation: Objects in JavaScript are dynamic and allow adding new properties at runtime using either dot or bracket notation.