O'Reilly logo

The JavaScript Programming Language by John David Dionisio, Ray Toal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

chapter 3

Functions

A function is an object that carries out a specific computation; it is written once but can be run over and over again. This chapter illustrates how to define and use functions, spending some time on one of JavaScript's most useful and powerful features: the ability to pass functions as arguments to other functions.

3.1 Function Definitions and Function Calls

Conceptually, a function transforms inputs to outputs. Figure 3.1 shows the “computation” of an account balance after t years, given a starting balance p, and an annual percentage rate r, compounded n times per year.

In JavaScript, a function consists of a block of executable code, called its body, together with zero or more “inputs,” called parameters. The following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required