Chapter 4Functions

In the last chapter, we covered arrays, logic, and loops. In this chapter, we’re going to look at functions. A function is a chunk of code that is almost like a small, self-contained mini program that can be referenced by a name. They can help to reduce repetition and make code easier to follow.

In this chapter, we’ll be covering these topics:

  • defining functions―function declarations, function expressions, and Function() constructors

  • invoking a function

  • return values

  • parameters and arguments

  • scope―global and local

  • hoisting―variables and functions

  • callbacks―functions as a parameter

  • project―we’ll be using functions to make it simpler to understand the Quiz Ninja code

In JavaScript, functions are considered to be just ...

Get JavaScript: Novice to Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.