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