HTML and CSS Reference
In-Depth Information
J avaScript functions are powerful beasts. They are first class objects, meaning they
can be assigned to variables and as properties, passed as arguments to functions, have
properties of their own, and more. JavaScript also supports anonymous functions,
commonly used for inline callbacks to other functions and object methods.
In this chapter we will cover the somewhat theoretical side of JavaScript func-
tions, providing us with the required background to easily dive into the more in-
teresting uses of functions as we dig into into closures in Chapter 6, Applied Func-
tions and Closures, and methods and functions as a means to implement objects in
Chapter 7, Objects and Prototypal Inheritance.
5.1 Defining Functions
Throughout the first part of this topic we have already seen several ways to define
functions. In this section we will go over the different ways JavaScript allows us
to do so, and investigate their pros and cons as well as some unexpected browser
5.1.1 Function Declaration
The most straightforward way to define a function is by way of a function definition,
seen in Listing 5.1.
Search WWH ::

Custom Search