7. Creating Functions

In the past couple of chapters, you’ve used several functions built into JavaScript, but now it’s time to start writing your own. Out of necessity, Chapter 2, JavaScript in Action, explained how to write a most basic function, but in this chapter you’ll learn all the particulars of user-defined functions. Not only are user-defined functions necessary in JavaScript for event handling, but, as in any language, being able to create your own functions constitutes a huge step toward creating modular and easily reusable code. The chapter begins with the fundamentals, and slowly works its way into the more advanced concepts.

The Fundamentals

This chapter starts by walking through the basics of functions in JavaScript. Not only ...

Get Modern JavaScript: Develop and Design now with O’Reilly online learning.

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