Chapter 4: Functions

A function is a chunk of code that can be referenced by a name, and is almost like a small, self-contained mini program. Functions can help reduce repetition and make code easier to follow.

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

  • Defining functions―function declarations, function expressions, Function() constructors and the new arrow syntax

  • Invoking a function

  • Return values

  • Parameters and arguments

  • Hoisting―variables and functions

  • Callbacks―functions as a parameter

  • Project ― we’ll be using functions to make the Quiz Ninja code easier to follow

In JavaScript, functions are considered to be first-class objects. This means they behave in the same way as all the other primitive data types and objects in the ...

Get JavaScript: Novice to Ninja, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.