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