Chapter 7. Working with functions

After reading this chapter, you’ll be able to

  • Understand the purpose of functions in JavaScript.

  • Define your own functions.

  • Call functions and receive data back from them.

  • Understand some of the built-in functions in JavaScript.

What’s in a function?

A JavaScript function is a collection of statements, either named or unnamed (anonymous), that can be called from elsewhere within a JavaScript program. Functions can accept arguments, which are input values passed into the function. Within a function, those arguments passed into the function can be acted upon and the results returned to the caller of the function via a return value.

Functions are perfect when you have something that needs to happen multiple times ...

Get JavaScript Step by Step 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.