O'Reilly logo

Head First JavaScript Programming by Elisabeth Robson, Eric T. Freeman

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 11. Serious functions

Anonymous Functions, Scope and Closures

image with no caption

You’ve put functions through their paces, but there’s more to learn. In this chapter we take it further; we get hard-core. We’re going to show you how to really handle functions. This won’t be a super long chapter, but it will be intense, and at the end you’re going to be more expressive with your JavaScript than you thought possible. You’re also going to be ready to take on a coworker’s code, or jump into an open source JavaScript library, because we’re going to cover some common coding idioms and conventions around functions. And if you’ve never heard of an anonymous function or a closure, boy are you in the right place.

Note

And if you have heard of a closure, but don’t quite know what it is, you’re even more in the right place!

Taking a look at the other side of functions...

image with no caption

You’ve already seen two sides of functions—you’ve seen the formal, declarative side of function declarations, and you’ve seen the looser, more expressive side of function expressions. Well, now it’s time to introduce you to another interesting side of functions: the anonymous side.

By anonymous we’re referring to functions that don’t have names. How can that happen? Well, when you define a function with a function declaration, your function will ...

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