Recap

Grade 10, page 12 of 12. A one-minute read.

  • A callback is a function passed into another function. A higher-order function takes or returns functions.
  • forEach runs a function for each item. It can't be stopped early.
  • map transforms each item and returns a new array of the same length. Don't forget return if you use curly braces!
  • filter keeps items whose callback returns truthy, and returns a new, possibly shorter array.
  • find returns the first matching item (or undefined). findIndex returns its index (or -1).
  • some checks if any item passes. every checks if all items pass.
  • reduce combines all items into one value, using an accumulator. Always provide a starting value.
  • sort's comparison function returns negative (a first), positive (b first) or zero. Use a - b for numbers and localeCompare for strings. Sort a copy to protect the original.
  • Chain methods together to build readable data pipelines.

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning