MCQs on Advanced Array Methods | JavaScript Advanced

Discover the power of JavaScript arrays with advanced methods like reduce, find, some, and every. Learn sorting, filtering, destructuring, and explore nested arrays with flat and flatMap. Dive in!


1. Array Methods: reduce, find, some, every

  1. Which method executes a reducer function on each array element to produce a single output value?
    a) reduce
    b) find
    c) some
    d) every
  2. What does the find method return when no element satisfies the condition?
    a) null
    b) undefined
    c) An empty array
    d) false
  3. Which method tests whether at least one array element passes the provided function?
    a) reduce
    b) find
    c) some
    d) every
  4. The every method checks if:
    a) Any element meets the condition.
    b) All elements meet the condition.
    c) At least one element meets the condition.
    d) No elements meet the condition.
  5. What does reduce require as its first argument?
    a) A callback function.
    b) A condition.
    c) A boolean.
    d) An array.
  6. How many parameters does the callback function of reduce accept?
    a) 1
    b) 2
    c) 3
    d) 4
  7. What happens if you don’t provide an initial value to reduce?
    a) Throws an error.
    b) Uses undefined as the initial value.
    c) Uses the first element of the array.
    d) Skips the first iteration.
  8. Which method stops searching once it finds the first match?
    a) reduce
    b) find
    c) some
    d) every
  9. If some finds a match, it immediately returns:
    a) true
    b) false
    c) The matched value.
    d) An error.
  10. Can every return true for an empty array?
    a) Yes
    b) No

2. Sorting and Filtering Arrays

  1. What method sorts the elements of an array in place?
    a) sort
    b) filter
    c) flat
    d) flatMap
  2. What does sort use to compare elements by default?
    a) Lexicographical order
    b) Numerical order
    c) Boolean values
    d) Random order
  3. Which method creates a new array with elements that pass a specific condition?
    a) filter
    b) sort
    c) flat
    d) flatMap
  4. What is the return type of filter when no elements satisfy the condition?
    a) null
    b) An empty array
    c) undefined
    d) The original array
  5. Which method modifies the original array?
    a) filter
    b) sort
    c) Both
    d) Neither
  6. How can you sort numbers in ascending order using sort?
    a) Pass a callback (a, b) => a - b.
    b) Pass a callback (a, b) => b - a.
    c) Use filter instead of sort.
    d) Use flat.
  7. What type of method is filter?
    a) Mutating
    b) Non-mutating

3. Array Destructuring

  1. What does array destructuring allow you to do?
    a) Clone an array.
    b) Assign array values to variables.
    c) Sort array elements.
    d) Flatten nested arrays.
  2. Which syntax correctly destructures the first two elements of an array?
    a) {a, b} = array
    b) [a, b] = array
    c) (a, b) = array
    d) <a, b> = array
  3. What happens if the array has fewer elements than the destructured variables?
    a) Throws an error.
    b) Assigns undefined to extra variables.
    c) Skips destructuring.
    d) Stops execution.
  4. How can you skip elements during destructuring?
    a) Use commas without variables.
    b) Use null.
    c) Use an empty object.
    d) Use undefined.
  5. Destructuring can be used with:
    a) Only arrays.
    b) Only objects.
    c) Arrays and objects.

4. Nested Arrays and flat, flatMap Methods

  1. What does the flat method do?
    a) Sorts the array.
    b) Flattens nested arrays.
    c) Filters the array.
    d) Maps each element.
  2. What parameter does flat accept?
    a) A callback function.
    b) A depth level.
    c) A sorting condition.
    d) An array.
  3. What is the default depth for the flat method?
    a) 1
    b) 2
    c) Infinity
    d) 0
  4. Which method combines mapping and flattening?
    a) filter
    b) flat
    c) flatMap
    d) reduce
  5. What is a key difference between flat and flatMap?
    a) flat modifies the original array.
    b) flatMap performs a mapping before flattening.
    c) flatMap works on objects only.
    d) flat sorts the array.
  6. Which method is more efficient for combining map and flat?
    a) map followed by flat
    b) flatMap
  7. What happens if you call flat(Infinity) on a deeply nested array?
    a) Flattens completely.
    b) Throws an error.
    c) Returns the original array.
    d) Only flattens once.
  8. Can flatMap alter the number of elements in the array?
    a) Yes
    b) No

Answers

QNoAnswer
1a) reduce
2b) undefined
3c) some
4b) All elements meet the condition.
5a) A callback function.
6d) 4
7c) Uses the first element of the array.
8b) find
9a) true
10a) Yes
11a) sort
12a) Lexicographical order
13a) filter
14b) An empty array
15b) sort
16a) Pass a callback (a, b) => a - b.
17b) Non-mutating
18b) Assign array values to variables.
19b) [a, b] = array
20b) Assigns undefined to extra variables.
21a) Use commas without variables.
22c) Arrays and objects
23b) Flattens nested arrays.
24b) A depth level
25a) 1
26c) flatMap
27b) flatMap performs a mapping before flattening.
28b) flatMap
29a) Flattens completely
30a) Yes

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top