5. Functions

Functions are remarkably flexible in JavaScript. That flexibility provides a lot of power, but it can also create confusion, especially in how functions interact with variables and objects. This chapter covers some pretty advanced concepts; some nuances might not stick with you right away, but once you spend some time with functions, you’ll really start to appreciate the power of the JavaScript language.

Creating Functions

The two ways to create functions both use the function keyword, so the differences between them aren’t immediately apparent.

Declarations

Variable declarations and function declarations operate similarly. They start with a keyword (var or function), followed by an identifier. Function declarations add lists ...

Get The JavaScript PocketGuide now with O’Reilly online learning.

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