function statement JS Home  <<  JS Reference  <<  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.


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.


Signature Description
function functionName ([arg1[, arg2[, ... argN]){
Allows us to create a Function declaration using a statement.


Parameter Description
arg1, arg2, ..., argNFormal argument names to be used by the function:
  • A comma(,) delimited list of strings that correspond to valid JavaScript identifiers ('a', 'b', 'c',...)
  • A comma(,) delimited string where each entry corresponds to a valid JavaScript identifier ('a, b, c...')
  • Arguments passed are treated as the names of the parameter identifiers of the function. The function is created with the arguments in the order in which they are passed.
statementsThe JavaScript statements that comprise the function definition.


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;


Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 8 - Functions