Exercise Wednesday

Goal: Now that we've learned about Array.prototype.map(), let's further hone our array mapping skills by completing the exercises detailed below.

Warm Up


  • What is a callback function? How is it different from a plain old function?
  • What portion of the following code is the callback function? What does this particular callback function do?
const tripledNumbers = numbers.map(function(number) {
  return number * 3;
});
  • Does map() alter the array it is called upon?
  • Discuss with your partner when you would use forEach() and when it might be better to use map().

Code


Array Mapping Practice

Complete the following in the JavaScript console or on JSFiddle:

  • Make an array of numbers, then use .map() to return an array containing each of the original numbers + 1.
  • Create an array of words. Use .map() to return an array of the same words in all uppercase.

Lesson 23 of 31
Last updated June 22, 2020