O'Reilly logo

JavaScript Step by Step by Steve Suehring

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 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 within ...

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