Chapter 7

Using Functions

In This Chapter

arrow Working with built-in functions

arrow Using the Math object functions

arrow Creating your own functions

arrow Understanding how to create private data

In previous chapters, you see a multitude of both built-in and custom functions, but you don't really work through all of the intricacies of functions. In addition, JavaScript offers far more in the way of functions than the few you see in earlier chapters. This chapter focuses on the JavaScript function. It begins by introducing you to more built-in functions, especially those provided by the Math object. After that, you begin creating your own custom functions.

This chapter introduces you to some new concepts when it comes to functions. For example, you discover the best time to separate code into a new function rather than keeping it part of an existing function. You also find some techniques for passing both required and optional parameters (arguments) to functions and returning data to the caller.

Perhaps the most controversial topic in the chapter is using private data with JavaScript. Some developers ...

Get HTML5 Programming with JavaScript For Dummies now with O’Reilly online learning.

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