Question 7
Back to Exercise
What does typeof [1, 2, 3] return, and how should you test for an array?
- A "array" – typeof is enough
- B "list" – use instanceof List
- C "object" – use value.length > 0
- D "object" – use Array.isArray(value) Correct
Correct Answer: Option D
Arrays are objects, so typeof cannot tell them apart. Array.isArray is reliable, even across iframes.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!