FUNCTIONS
Functions are the core of any language because they allow the encapsulation of statements that can be run anywhere and at any time. Functions in ECMAScript are declared using the function
keyword, followed by a set of arguments and then the body of the function.
The basic function syntax is as follows:
function functionName(arg0, arg1,…,argN) {
statements
}
Here's an example:
function sayHi(name, message) {
console.log("Hello " + name + ", " + message);
}
This function can then be called by using the function name, followed by the function arguments enclosed in parentheses (and separated by commas, if there are multiple arguments). The code to call the sayHi()
function looks like this:
sayHi("Nicholas", "how are you today?");
The output of this function call is, "Hello Nicholas, how are you today?"
The named arguments...