Java Reference
In-Depth Information
Chapter
4
Functions
In the last chapter, we covered arrays, logic, and loops. In this chapter, we're going to look
at functions. A function is a chunk of code that is almost like a small, self-contained mini
program that can be referenced by a name. They can help to reduce repetition and make code
easier to follow.
In this chapter, we'll be covering these topics:
• defining functions―function declarations, function expressions, and Func-
tion() constructors
• invoking a function
• return values
• parameters and arguments
• scope―global and local
• hoisting―variables and functions
• callbacks―functions as a parameter
• project―we'll be using functions to make it simpler to understand the Quiz Ninja
code
In JavaScript, functions are considered to be just another value. This means that they do all
the same tasks that other values and objects can do, such as be assigned to variables, changed
and stored in arrays. You can even define a function inside another function. In technical
terms, this means that functions are considered to be first-class objects in JavaScript.
This makes functions a very important and powerful part of the JavaScript language with
many of its features relying on them. Hence, fully understanding functions is an essential
skill of the JavaScript ninja.
Search WWH ::




Custom Search