Function

The Function object represents a function.

Every function is a Function object.

Functions can be created with function declarations, function expressions, and the Function constructor.

Function declaration:

function sum(a, b) {
  return a + b
}

Function expression:

const sum = function(a, b) {
  return a + b
}

Arrow function:

const sum = (a, b) => sum(a, b)

Function as a method:

const Arithmetic = {
  sum(a, b) {
    return a + b
  }
}

Function constructor:

const sum = new Function('a', 'b', 'return a + b')

Syntax

Function

Properties

Prototype Properties