function
statementS2C Home « Statements « function
Functions are created using the global object constructor new Function()
, via declaration using the function
statement, or by function expression using the
function
operator.
All functions are Function
objects undernath the covers, but as mentioned above there are different ways to set up the function creation.
Description
The function
statement allows us to create a Function
declaration using a statement.
- Function objects created this way are parsed with the rest of the JavaScript code and so are more efficient than functions created using the constructor creation method.
Syntax
Signature | Description |
---|---|
function functionName ([arg1[, arg2[, ... argN]){ | Allows us to create a Function declaration using a statement. |
Parameters
Parameter | Description |
---|---|
arg1, arg2, ..., argN | Formal argument names to be used by the function:
|
statements | The JavaScript statements that comprise the function definition. |
Examples
The code below gives an example of using the function
statement.
*/
/ Create a function statement that takes an argument and
/ returns the square of the argument.
/*
function show_functionStatement() {
function squareNumber(a) {
return a * a;
}
alert(squareNumber(9));
alert(squareNumber(13));
}
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 8 - Functions