Summary: Let’s Get Functional

Review what we learned about functions in JavaScript.

We'll cover the following

Key points

  • Named parameters can be reproduced in JavaScript using an object as the parameter. This allows the arguments to be provided as properties of the object in any order.
  • The rest parameter allows any number of values to be provided to a function as an array.
  • Recursive functions are functions that continually call themselves until a certain condition is reached.
  • The scope of a variable determines where and how that variable can be accessed.
  • Functions declared using the function keyword are hoisted to the top of the scope, meaning they can be called even before they’ve been defined.
  • Variables should be declared before they’re referred to.
  • A closure is formed when a function accesses a variable that has been declared in the surrounding scope of the function. By returning the function, we can maintain access to the variable outside the scope it was declared in.
  • Functional programming is a style of programming that combines pure functions that perform a single task in order to perform more complex tasks.
  • Pure functions shouldn’t reference anything outside the scope of the function that has not been supplied as an argument, and they shouldn’t cause side effects by changing anything outside the scope of the function. They should have referential transparency, which means that, given the same arguments, they should return the same value.
  • Higher-order functions accept functions as arguments and return functions. They can be chained together to complete more complex operations.

Get hands-on with 1200+ tech skills courses.