Javascript - Function Function Type


Javascript functions are objects.

Each function is an instance of the Function type which has properties and methods.

Function names are pointers to function objects.

Functions are typically defined using function-declaration syntax:

function sum (num1, num2) {
    return num1 + num2;

You can use a function expression to define the same function:

var sum = function(num1, num2){
    return num1 + num2;

In code above, sum is defined and initialized to be a function.

The function can be referenced by the variable sum.

There is a semicolon after the end of the function.

You can define functions using the Function constructor, which accepts any number of arguments.

The last argument is the function body, and the previous arguments are the new function's arguments.

var sum = new Function("num1", "num2", "return num1 + num2");   //not recommended

The code above illustrates that

  • functions are objects and
  • function names are pointers to the function object.