Function Definition Expressions
A function definition expression defines a JavaScript function,
and the value of such an expression is the newly defined function. In
a sense, a function definition expression is a “function literal” in
the same way that an object initializer is an “object literal.” A
function definition expression typically consists of the keyword
function followed by a
comma-separated list of zero or more identifiers (the parameter names)
in parentheses and a block of JavaScript code (the function body) in
curly braces. For example:
// This function returns the square of the value passed to it.varsquare=function(x){returnx*x;};
A function definition expression can also include a name for the function. Functions can also be defined using a function statement rather than a function expression. Complete details on function definition are in Chapter 8.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access