JavaScript Arrays MCQs for Developer Interviews & Certification

1 min read

Arrays in JavaScript are high-level, list-like objects used to store ordered collections of elements of varying data types. Zero-indexed and dynamically resizable, JavaScript arrays come with built-in prototype methods for adding (push, unshift), removing (pop, shift), transforming (map, filter, reduce), and reorganizing (sort, reverse, splice) data. Modern ECMAScript standards (ES6+) introduced features such as array destructuring, the spread operator (...), and non-mutating array copy methods (toSorted, toSpliced, toReversed, with). Understanding how array mutation works, how sparse arrays behave, and how iterative callbacks operate is vital for clean web development and technical coding assessments.

1. What is the output of Array.isArray([1, 2, 3])?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Array.isArray() is the standard method to verify if a given value is an instance of Array.

2. Which method removes the last element from an array and returns that element?

a) shift()
b) pop()
c) unshift()
d) push()
Correct Answer: b) pop()
Explanation:
The pop() method mutates the array by removing its final element and returning that removed element.

3. Which method adds one or more elements to the end of an array and returns the new length?

a) push()
b) unshift()
c) concat()
d) splice()
Correct Answer: a) push()
Explanation:
The push() method appends new elements to the end of an array and returns the array's updated length.

4. Which method removes the first element from an array and returns that element?

a) pop()
b) shift()
c) unshift()
d) slice()
Correct Answer: b) shift()
Explanation:
The shift() method removes the element at index 0, shifts all remaining elements down, and returns the removed element.

5. Which method adds one or more elements to the beginning of an array and returns the new length?

a) unshift()
b) push()
c) shift()
d) splice()
Correct Answer: a) unshift()
Explanation:
The unshift() method inserts new elements at index 0 of an array and returns the new length.

6. What is the output of [10, 20, 30].indexOf(20)?

a) 1
b) 2
c) 0
d) -1
Correct Answer: a) 1
Explanation:
indexOf() returns the first index at which a given element can be found in the array.

7. What is returned by [1, 2, 3].indexOf(5)?

a) -1
b) undefined
c) null
d) false
Correct Answer: a) -1
Explanation:
When an element is not present in the target array, indexOf() returns -1.

8. Which method creates a new array populated with the results of calling a provided function on every element?

a) forEach()
b) map()
c) filter()
d) reduce()
Correct Answer: b) map()
Explanation:
map() transforms each element of an array using a callback function and returns a new array of the same length.

9. Which method creates a shallow copy of a portion of an array containing elements that pass a test function?

a) map()
b) filter()
c) some()
d) every()
Correct Answer: b) filter()
Explanation:
filter() creates a new array containing only elements that evaluate to true in the provided testing callback.

10. What is the return value of the Array.prototype.forEach() method?

a) A new array
b) The original array
c) undefined
d) The total number of items
Correct Answer: c) undefined
Explanation:
forEach() executes a provided function once for each array element and always returns undefined.

11. What is the output of [1, 2, 3, 4].slice(1, 3)?

a) [2, 3]
b) [2, 3, 4]
c) [1, 2]
d) [3, 4]
Correct Answer: a) [2, 3]
Explanation:
slice(start, end) extracts elements from start index up to, but not including, the end index.

12. Does Array.prototype.slice() mutate the original array?

a) Yes
b) No
c) Only if negative indices are passed
d) Only when used on sparse arrays
Correct Answer: b) No
Explanation:
slice() is a non-mutating method that returns a shallow copy of the selected portion of the array.

13. Does Array.prototype.splice() mutate the original array?

a) Yes
b) No
c) Only when deleting items
d) Only when inserting items
Correct Answer: a) Yes
Explanation:
splice() modifies the content of an array in place by removing, replacing, or adding elements.

14. What does [1, 2, 3, 4, 5].splice(2, 2) return?

a) [3, 4]
b) [1, 2, 5]
c) [2, 3]
d) [3]
Correct Answer: a) [3, 4]
Explanation:
splice(start, deleteCount) returns an array containing the elements that were removed from index 2.

15. What is the output of [1, 2, 3].includes(2)?

a) true
b) false
c) 1
d) undefined
Correct Answer: a) true
Explanation:
includes() determines whether an array includes a certain value among its entries, returning true or false.

16. How does includes() handle NaN compared to indexOf()?

a) includes() finds NaN, whereas indexOf() returns -1.
b) indexOf() finds NaN, whereas includes() returns false.
c) Both methods find NaN correctly.
d) Both methods return -1 for NaN.
Correct Answer: a) includes() finds NaN, whereas indexOf() returns -1.
Explanation:
includes() uses the SameValueZero comparison algorithm which handles NaN, whereas indexOf uses strict equality (===).

17. What is the result of [10, 20, 30].find(x => x > 15)?

a) 20
b) [20, 30]
c) 1
d) true
Correct Answer: a) 20
Explanation:
find() returns the value of the first element in the array that satisfies the provided testing function.

18. What is the result of [10, 20, 30].findIndex(x => x > 15)?

a) 1
b) 20
c) 2
d) -1
Correct Answer: a) 1
Explanation:
findIndex() returns the index of the first element in the array that satisfies the testing function.

19. What does find() return if no element satisfies the testing function?

a) undefined
b) -1
c) null
d) []
Correct Answer: a) undefined
Explanation:
If no elements pass the search condition, find() returns undefined.

20. What does findIndex() return if no element satisfies the testing function?

a) -1
b) undefined
c) null
d) false
Correct Answer: a) -1
Explanation:
If no elements pass the testing condition, findIndex() returns -1.

21. What is the output of [1, 2, 3].concat([4, 5])?

a) [1, 2, 3, 4, 5]
b) [[1, 2, 3], [4, 5]]
c) [1, 2, 3, [4, 5]]
d) 1,2,3,4,5
Correct Answer: a) [1, 2, 3, 4, 5]
Explanation:
concat() merges two or more arrays and returns a new combined array.

22. What is the output of [1, 2, 3].join('-')?

a) 1-2-3
b) ["1-2-3"]
c) 1,2,3
d) 123
Correct Answer: a) 1-2-3
Explanation:
join() creates and returns a new string by concatenating all array elements separated by the specified string.

23. What separator does Array.prototype.join() use by default if none is provided?

a) ,
b) empty string
c) space
d) -
Correct Answer: a) ,
Explanation:
If no separator argument is supplied to join(), it defaults to separating items with a comma.

24. What is the output of [1, 2, 3, 4].reduce((acc, curr) => acc + curr, 0)?

a) 10
b) 24
c) [10]
d) undefined
Correct Answer: a) 10
Explanation:
reduce() executes a reducer callback on each element, summing 0 + 1 + 2 + 3 + 4 to result in 10.

25. What occurs when reduce() is called on an empty array without an initial value?

a) TypeError
b) undefined
c) 0
d) null
Correct Answer: a) TypeError
Explanation:
Executing reduce() on an empty array with no initial value throws a TypeError.

26. What is the output of [1, 2, 3].every(x => x > 0)?

a) true
b) false
c) undefined
d) 1
Correct Answer: a) true
Explanation:
every() tests whether all elements in the array pass the provided condition.

27. What is the output of [1, 2, 3].some(x => x > 2)?

a) true
b) false
c) 3
d) undefined
Correct Answer: a) true
Explanation:
some() tests whether at least one element in the array passes the testing function.

28. What will [].every(x => x > 0) return?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
every() returns true for any condition when called on an empty array (vacuous truth).

29. What will [].some(x => x > 0) return?

a) false
b) true
c) undefined
d) TypeError
Correct Answer: a) false
Explanation:
some() returns false for any condition when called on an empty array.

30. What is the output of Array.from('cat')?

a) ["c", "a", "t"]
b) ["cat"]
c) cat
d) TypeError
Correct Answer: a) ["c", "a", "t"]
Explanation:
Array.from() creates a new array instance from an iterable object such as a string.

31. What is the output of Array.of(7)?

a) [7]
b) An empty array of length 7
c) 7
d) undefined
Correct Answer: a) [7]
Explanation:
Array.of(7) creates a new Array instance with a single element [7], regardless of type or quantity of arguments.

32. What is the difference between Array.of(3) and new Array(3)?

a) Array.of(3) creates [3]; new Array(3) creates an array with 3 empty slots.
b) Array.of(3) creates 3 empty slots; new Array(3) creates [3].
c) There is no difference.
d) new Array(3) throws a SyntaxError.
Correct Answer: a) Array.of(3) creates [3]; new Array(3) creates an array with 3 empty slots.
Explanation:
Passing a single number to new Array(N) sets the length to N with empty slots, while Array.of(N) creates [N].

33. What is the output of [1, [2, [3]]].flat()?

a) [1, 2, [3]]
b) [1, 2, 3]
c) [1, [2, [3]]]
d) [[1, 2, 3]]
Correct Answer: a) [1, 2, [3]]
Explanation:
The flat() method flattens sub-array structures up to a default depth of 1.

34. How can you completely flatten an array of arbitrary nesting depth?

a) arr.flat(Infinity)
b) arr.flat(ALL)
c) arr.flatDeep()
d) arr.flatten()
Correct Answer: a) arr.flat(Infinity)
Explanation:
Passing Infinity as the depth parameter to flat() recursively flattens all nested arrays.

35. What does [1, 2, 3].flatMap(x => [x, x * 2]) return?

a) [1, 2, 2, 4, 3, 6]
b) [[1, 2], [2, 4], [3, 6]]
c) [1, 4, 9]
d) [2, 4, 6]
Correct Answer: a) [1, 2, 2, 4, 3, 6]
Explanation:
flatMap() first maps each element using a mapping function, then flattens the result by depth 1.

36. What is the default sort order when calling Array.prototype.sort() without parameters?

a) String Unicode code point order
b) Ascending numerical order
c) Descending numerical order
d) Insertion order
Correct Answer: a) String Unicode code point order
Explanation:
By default, sort() converts elements to strings and compares their UTF-16 code units.

37. What is the output of [1, 10, 2, 21].sort()?

a) [1, 10, 2, 21]
b) [1, 2, 10, 21]
c) [21, 10, 2, 1]
d) [2, 1, 21, 10]
Correct Answer: a) [1, 10, 2, 21]
Explanation:
Default string sorting places '10' before '2' because character '1' comes before '2'.

38. How do you correctly sort numbers in ascending numerical order using sort()?

a) arr.sort((a, b) => a - b)
b) arr.sort((a, b) => b - a)
c) arr.sort(ascending)
d) arr.sort()
Correct Answer: a) arr.sort((a, b) => a - b)
Explanation:
The comparator function (a, b) => a - b returns a negative value if a < b, ordering numbers numerically.

39. Does Array.prototype.sort() mutate the original array?

a) Yes
b) No
c) Only when sorting objects
d) Only when a comparator function is supplied
Correct Answer: a) Yes
Explanation:
sort() modifies the original array in place and returns a reference to the same array.

40. Which ES2023 method returns a sorted copy of an array without mutating the original?

a) toSorted()
b) sortCopy()
c) sliceSort()
d) sorted()
Correct Answer: a) toSorted()
Explanation:
toSorted() was introduced in ES2023 as a non-mutating version of sort().

41. Which ES2023 method returns a reversed copy of an array without mutating the original?

a) toReversed()
b) reverseCopy()
c) reversed()
d) sliceReverse()
Correct Answer: a) toReversed()
Explanation:
toReversed() returns a new array with elements in reversed order without changing the original array.

42. Which ES2023 method returns a new array with a modified value at a specified index without mutating the original?

a) with()
b) set()
c) replace()
d) at()
Correct Answer: a) with()
Explanation:
The with(index, value) method returns a copy of the array with the element at the specified index replaced.

43. What is the output of [10, 20, 30].at(-1)?

a) 30
b) 10
c) undefined
d) NaN
Correct Answer: a) 30
Explanation:
The at() method supports negative integers to count back from the end of the array (-1 is the last item).

44. What is the output of [10, 20, 30][-1]?

a) undefined
b) 30
c) TypeError
d) null
Correct Answer: a) undefined
Explanation:
Standard bracket notation does not support negative indices and attempts to look up property key '-1'.

45. What is the output of [1, 2, 3].fill(0, 1, 3)?

a) [1, 0, 0]
b) [0, 0, 0]
c) [1, 0, 3]
d) [0, 2, 3]
Correct Answer: a) [1, 0, 0]
Explanation:
fill(value, start, end) changes array elements to a static value from start index up to end index.

46. What is the output of [1, 2, 3, 4, 5].copyWithin(0, 3)?

a) [4, 5, 3, 4, 5]
b) [1, 2, 3, 4, 5]
c) [4, 5, 1, 2, 3]
d) [3, 4, 5, 4, 5]
Correct Answer: a) [4, 5, 3, 4, 5]
Explanation:
copyWithin(target, start) copies array elements from start index to target position in place.

47. What is the output of [1, 2, 3].keys() when converted to an array using Array.from()?

a) [0, 1, 2]
b) [1, 2, 3]
c) ["0", "1", "2"]
d) []
Correct Answer: a) [0, 1, 2]
Explanation:
keys() returns an Array Iterator containing the indices (0, 1, 2) of the array.

48. What is the output of Array.from([10, 20].values())?

a) [10, 20]
b) [0, 1]
c) [10]
d) undefined
Correct Answer: a) [10, 20]
Explanation:
values() returns an Array Iterator containing the values of the array.

49. What is the output of Array.from([10, 20].entries())?

a) [[0, 10], [1, 20]]
b) ["0:10", "1:20"]
c) [10, 20]
d) [0, 1]
Correct Answer: a) [[0, 10], [1, 20]]
Explanation:
entries() returns an iterator yielding key/value pairs [index, element] for each item.

50. What happens to the array when its length property is manually set to a smaller number `let a = [1, 2, 3]; a.length = 1;`?

a) The array is truncated in place, removing trailing items.
b) The length property changes but elements remain stored.
c) A RangeError is thrown.
d) Nothing happens.
Correct Answer: a) The array is truncated in place, removing trailing items.
Explanation:
Truncating the length property removes all elements whose indices are greater than or equal to the new length.

51. What happens when you execute `let a = [1, 2]; a.length = 0;`?

a) The array is completely emptied.
b) The array remains unchanged.
c) It causes a TypeError.
d) a becomes undefined.
Correct Answer: a) The array is completely emptied.
Explanation:
Setting length to 0 deletes all elements in the array in place.

52. What happens if you assign a negative number to an array's length property `arr.length = -1`?

a) RangeError
b) TypeError
c) Array becomes empty
d) Length is set to 0
Correct Answer: a) RangeError
Explanation:
Assigning an invalid, negative, or non-integer length value throws a RangeError.

53. What is a sparse array in JavaScript?

a) An array with unassigned indices (empty slots or holes)
b) An array containing only null values
c) An array with zero elements
d) An immutable array
Correct Answer: a) An array with unassigned indices (empty slots or holes)
Explanation:
A sparse array is one in which elements are non-contiguous and length exceeds element count.

54. How does Array.prototype.forEach() handle empty slots (holes) in sparse arrays?

a) It skips unassigned empty slots entirely.
b) It invokes the callback with undefined.
c) It throws a TypeError.
d) It replaces holes with null.
Correct Answer: a) It skips unassigned empty slots entirely.
Explanation:
Built-in array iteration methods like forEach, map, and filter skip empty slots in sparse arrays.

55. How does for...of handle empty slots (holes) in sparse arrays?

a) It iterates over empty slots yielding undefined.
b) It skips empty slots.
c) It throws a TypeError.
d) It stops the loop.
Correct Answer: a) It iterates over empty slots yielding undefined.
Explanation:
The for...of loop uses the array iterator, which treats empty slots as having the value undefined.

56. What is the result of delete arr[1] on `let arr = [10, 20, 30]`?

a) Index 1 is deleted leaving an empty slot; length remains 3.
b) Index 1 is removed and length becomes 2.
c) Throws a TypeError.
d) Sets index 1 to null.
Correct Answer: a) Index 1 is deleted leaving an empty slot; length remains 3.
Explanation:
The delete operator removes the property at index 1 without re-indexing remaining items or changing array length.

57. What is the result of [1, 2, 3] == [1, 2, 3]?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
Arrays are object reference types in JavaScript. Comparing distinct array references evaluates to false.

58. What is the result of [1, 2, 3] === [1, 2, 3]?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
Two distinct array instances occupy different memory addresses, making reference comparison false.

59. How can you make a shallow copy of an array `arr`?

a) [...arr]
b) arr.slice()
c) Array.from(arr)
d) All of the above
Correct Answer: d) All of the above
Explanation:
Spread operator, slice(), and Array.from() are all standard methods to create a shallow copy of an array.

60. Which global function can perform a deep copy of an array containing nested objects?

a) structuredClone()
b) Array.deepCopy()
c) Object.clone()
d) arr.copyDeep()
Correct Answer: a) structuredClone()
Explanation:
structuredClone() is a standard built-in global function that creates deep copies of JavaScript values and data structures.

61. What is the result of [...'hello']?

a) ["h", "e", "l", "l", "o"]
b) ["hello"]
c) hello
d) TypeError
Correct Answer: a) ["h", "e", "l", "l", "o"]
Explanation:
Applying the spread operator to a string spreads its individual characters into array elements.

62. What is the result of [1, 2, 3].lastIndexOf(2)?

a) 1
b) 2
c) 0
d) -1
Correct Answer: a) 1
Explanation:
lastIndexOf() searches the array backwards and returns the last index at which a value is found.

63. What is the output of [1, 2, 3, 2, 1].lastIndexOf(2)?

a) 3
b) 1
c) 2
d) -1
Correct Answer: a) 3
Explanation:
The last occurrence of value 2 in [1, 2, 3, 2, 1] is located at index position 3.

64. What does [1, 2, 3].reduceRight((acc, curr) => acc + curr, '') return?

a) "321"
b) "123"
c) 6
d) TypeError
Correct Answer: a) "321"
Explanation:
reduceRight() processes elements from right to left, concatenating '3' + '2' + '1' into '321'.

65. Which method tests whether an object is a TypedArray or standard Array?

a) Array.isArray() returns true only for standard Array instances.
b) Array.isArray() returns true for both TypedArray and standard Array.
c) typeof returns 'array' for both.
d) Array.isArray() returns false for standard Array.
Correct Answer: a) Array.isArray() returns true only for standard Array instances.
Explanation:
Array.isArray() explicitly evaluates to false for TypedArray instances (e.g., Int8Array).

66. What is the output of [10, 20, 30].findLast(x => x < 25) in ES2023?

a) 20
b) 10
c) 30
d) undefined
Correct Answer: a) 20
Explanation:
findLast() searches backwards from the end and returns the first element that satisfies the condition (20).

67. What is the output of [10, 20, 30].findLastIndex(x => x < 25) in ES2023?

a) 1
b) 0
c) 2
d) -1
Correct Answer: a) 1
Explanation:
findLastIndex() searches backwards and returns the index of the first matching element (index 1 for value 20).

68. What happens if you access an out-of-bounds index on an array `[1, 2][5]`?

a) undefined
b) RangeError
c) null
d) ReferenceError
Correct Answer: a) undefined
Explanation:
Accessing a non-existent property/index on an array returns undefined.

69. What will `let a = [1, 2]; a[4] = 5; console.log(a.length);` output?

a) 5
b) 3
c) 2
d) 4
Correct Answer: a) 5
Explanation:
Setting element at index 4 automatically updates the array length property to index + 1 = 5.

70. What is the output of `[1, 2, 3].map(parseInt)`?

a) [1, NaN, NaN]
b) [1, 2, 3]
c) [NaN, NaN, NaN]
d) [1, 2, NaN]
Correct Answer: a) [1, NaN, NaN]
Explanation:
map passes (element, index) to parseInt. parseInt(1, 0) is 1; parseInt(2, 1) is NaN; parseInt(3, 2) is NaN.

71. How can you safely parse string numbers in an array using map() without radix issues?

a) ['1', '2', '3'].map(Number)
b) ['1', '2', '3'].map(x => parseInt(x, 10))
c) Both a and b
d) ['1', '2', '3'].map(parseInt)
Correct Answer: c) Both a and b
Explanation:
Passing Number or explicit arrow wrapper `x => parseInt(x, 10)` avoids index parameters being passed as radix.

72. What is the result of `let a = [1, 2, 3]; Object.freeze(a); a.push(4);` in strict mode?

a) TypeError: Cannot add property, object is not extensible
b) 4 is added successfully
c) Silent failure without error
d) SyntaxError
Correct Answer: a) TypeError: Cannot add property, object is not extensible
Explanation:
Object.freeze() prevents adding, deleting, or modifying array elements. Calling mutating methods throws a TypeError.

73. What is the result of `Array.prototype.toString.call([1, 2, 3])`?

a) "1,2,3"
b) "[object Array]"
c) [1, 2, 3]
d) undefined
Correct Answer: a) "1,2,3"
Explanation:
Array.prototype.toString joins elements with commas, returning '1,2,3'.

74. What is the result of `Object.prototype.toString.call([1, 2, 3])`?

a) "[object Array]"
b) "1,2,3"
c) "Array"
d) undefined
Correct Answer: a) "[object Array]"
Explanation:
Object.prototype.toString returns the internal [[Class]] tag string '[object Array]'.

75. What is the output of `[1, 2, 3].unshift()` with no arguments?

a) 3
b) 0
c) undefined
d) TypeError
Correct Answer: a) 3
Explanation:
unshift() called without arguments leaves the array unchanged and returns its current length (3).

76. What is the output of `[1, 2, 3].push()` with no arguments?

a) 3
b) 0
c) undefined
d) TypeError
Correct Answer: a) 3
Explanation:
push() called without arguments returns the current length of the array (3).

77. Which method can be used to merge multiple arrays into one new array?

a) concat()
b) merge()
c) append()
d) combine()
Correct Answer: a) concat()
Explanation:
concat() combines two or more arrays without altering existing arrays.

78. What is the output of `let arr = [1, 2, 3]; arr[10] = 10; console.log(arr.filter(x => x === undefined));`?

a) []
b) [undefined, undefined, undefined]
c) [10]
d) TypeError
Correct Answer: a) []
Explanation:
filter() skips unassigned empty slots in sparse arrays, so callback is never invoked for empty holes.

79. What will `console.log(1 in [, , ])` output?

a) false
b) true
c) undefined
d) TypeError
Correct Answer: a) false
Explanation:
Trailing comma syntax creates empty slots. Empty slots do not exist as properties, returning false.

80. What is the output of `[1, 2, 3].slice(1)`?

a) [2, 3]
b) [1]
c) [1, 2, 3]
d) [2]
Correct Answer: a) [2, 3]
Explanation:
When end index is omitted, slice extracts from start index to the end of the array.

81. What is the output of `[1, 2, 3].slice(5)`?

a) []
b) undefined
c) [3]
d) TypeError
Correct Answer: a) []
Explanation:
If start index is greater than or equal to array length, slice() returns an empty array.

82. What is the result of `[1, 2, 3].splice(1)`?

a) [2, 3]
b) [1]
c) []
d) [2]
Correct Answer: a) [2, 3]
Explanation:
When deleteCount is omitted in splice(), all elements from start index to array end are removed and returned.

83. What is the output of `let a = [1, 2, 3]; a.splice(1, 0, 99); console.log(a);`?

a) [1, 99, 2, 3]
b) [1, 99, 3]
c) [99, 1, 2, 3]
d) [1, 2, 3, 99]
Correct Answer: a) [1, 99, 2, 3]
Explanation:
Setting deleteCount to 0 in splice inserts elements at start index without removing existing items.

84. What is the result of `Array(3).fill(1)`?

a) [1, 1, 1]
b) [3, 3, 3]
c) [1]
d) [undefined, undefined, undefined]
Correct Answer: a) [1, 1, 1]
Explanation:
Array(3) creates an array of length 3 with empty slots, and fill(1) populates all slots with value 1.

85. What happens if fill() is used with an object `Array(2).fill({})`?

a) Each slot receives a reference to the exact same object.
b) Each slot receives a new distinct object copy.
c) Throws a TypeError.
d) Object is converted to string.
Correct Answer: a) Each slot receives a reference to the exact same object.
Explanation:
fill() populates the array with the exact reference passed, so modifying one item affects all slots.

86. Which of the following array methods executes asynchronously?

a) None of the standard Array prototype iteration methods are inherently asynchronous.
b) forEach()
c) map()
d) reduce()
Correct Answer: a) None of the standard Array prototype iteration methods are inherently asynchronous.
Explanation:
All standard Array methods (forEach, map, filter, etc.) run synchronously.

87. What is the output of `[1, 2, 3].map(async x => x * 2)`?

a) An array of unresolved Promises [Promise, Promise, Promise]
b) [2, 4, 6]
c) A single Promise resolving to [2, 4, 6]
d) TypeError
Correct Answer: a) An array of unresolved Promises [Promise, Promise, Promise]
Explanation:
Async functions always return Promises, so map() returns an array containing Promise objects.

88. How can you wait for all promises in an array generated by map() to resolve?

a) Promise.all(arr.map(asyncFn))
b) arr.map(asyncFn).await()
c) arr.awaitMap(asyncFn)
d) Promise.map(arr)
Correct Answer: a) Promise.all(arr.map(asyncFn))
Explanation:
Promise.all() accepts an array of Promises and returns a single Promise that resolves when all resolve.

89. What is the output of `[1, 2, 3].every(() => true)` on an empty array `[].every(() => true)`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
every() on an empty array returns true regardless of callback.

90. What is the result of `[1, 2, 3].some(() => false)` on an empty array `[].some(() => false)`?

a) false
b) true
c) undefined
d) TypeError
Correct Answer: a) false
Explanation:
some() on an empty array returns false regardless of callback.

91. What will `console.log(Array.prototype.isPrototypeOf([]))` output?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
Array.prototype lies directly in the prototype chain of literal arrays [].

92. What is the output of `[1, 2, 3].reverse()`?

a) [3, 2, 1]
b) [1, 2, 3]
c) 3,2,1
d) undefined
Correct Answer: a) [3, 2, 1]
Explanation:
reverse() inverts the array elements in place and returns the mutated array.

93. What is the output of `let a = [1]; let b = a.reverse(); b.push(2); console.log(a);`?

a) [1, 2]
b) [1]
c) [2, 1]
d) [2]
Correct Answer: a) [1, 2]
Explanation:
reverse() returns a reference to the same original array object `a`. Mutating `b` mutates `a`.

94. What is the output of `[1, 2, 3].toString()`?

a) "1,2,3"
b) "[1, 2, 3]"
c) "1-2-3"
d) "[object Array]"
Correct Answer: a) "1,2,3"
Explanation:
Array.prototype.toString converts array elements to strings and joins them with commas.

95. What does `[1, [2, 3]].toString()` output?

a) "1,2,3"
b) "1,[2,3]"
c) "[1, [2, 3]]"
d) "1, 2, 3"
Correct Answer: a) "1,2,3"
Explanation:
toString on arrays recursively calls toString on nested arrays, flattening them into '1,2,3'.

96. Which method is used to determine if an array contains an element using strict equality?

a) includes()
b) find()
c) some()
d) search()
Correct Answer: a) includes()
Explanation:
includes() checks for presence using SameValueZero (similar to strict equality, but handles NaN).

97. What is the output of `[1, 2, 3].at(10)`?

a) undefined
b) RangeError
c) null
d) -1
Correct Answer: a) undefined
Explanation:
Accessing an out-of-bounds index using at() returns undefined.

98. What is the output of `[1, 2, 3].at(-3)`?

a) 1
b) 3
c) 2
d) undefined
Correct Answer: a) 1
Explanation:
Index -3 counts 3 positions back from array length 3, targeting index 0 (value 1).

99. Which method can convert an array-like object (having length property) to an Array?

a) Array.from()
b) Array.prototype.slice.call()
c) Spread operator [...obj] (if iterable)
d) All of the above
Correct Answer: d) All of the above
Explanation:
Array.from, slice.call, and spread (for iterables) are valid conversion techniques.

100. What is the output of `[1, 2, 3].findIndex(x => x === 10)`?

a) -1
b) undefined
c) false
d) null
Correct Answer: a) -1
Explanation:
findIndex returns -1 when no element matches the condition.

101. What is the output of `[1, 2, 3].find(x => x === 10)`?

a) undefined
b) -1
c) false
d) null
Correct Answer: a) undefined
Explanation:
find returns undefined when no element satisfies the test function.
← Previous: JavaScript Arrays & Array Methods MCQs
Next →: JavaScript Asynchronous Programming
No Image

C++ Templates - MCQs

1. What is the output of Array.isArray([1, 2, 3])? a) true b) false c) undefined d) TypeError Show Answer Correct…

By MCQs Generator
Java Advanced MCQs

Java Advanced MCQs

Advanced Java encompasses complex programming paradigms, low-level runtime mechanics, and high-performance framework design beyond standard syntax. It probes deep into…

By MCQs Generator
JavaScript Loops MCQs

JavaScript Loops MCQs

Iteration structures in JavaScript allow developers to execute code blocks repeatedly based on dynamic boolean conditions. Standard loops such as…

By MCQs Generator