JavaScript Array Methods: Intermediate Test
This intermediate JavaScript test covers the array methods developers use every day and the surprises hidden in them. Questions check why the default sort compares numbers as strings, why map(parseInt) returns NaN for some elements, why forEach returns undefined, how splice modifies an array in place while slice returns a copy, the TypeError reduce throws on an empty array without an initial value, how includes and indexOf treat NaN differently, what find and filter return when one or no element matches, why an arrow function with braces returns undefined inside map, what const does and does not protect on an array, and why sort returns the same array it sorted. Every code question is a complete program you can run with node in the sandbox to check your answer. The test has 10 multiple-choice questions with correct answers and an explanation for each.
Comments