7Creating functions

The graphical representation shows people dining out outside the restaurants on both sides of the road. The vehicles are passing through the road at the center.

What you will learn

Functions are an essential part of program design. You can use functions to break up a large solution into individual components and to create libraries of behaviors that can be used by your programs. We have used some built-in functions (for example, alert) and created event handler functions (for example, doCheckAge). In this chapter, you’ll learn how to create and use functions of your own. You’ll see how to give functions data to work on and how a program can receive results that a function returns. Along the way, you will pick up some tips about error handling.

What makes a function?

Parameters as ...

Get Begin to Code with JavaScript 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.