Function Expression
A function declaration is a standalone statement. But sometimes it is helpful to define a function as part of another expression, e.g., in an assignment, as a function parameter (callback) or as value in an Objects. This can be done with a function expression. It has the same syntax as a function declaration, only that the function name can be omitted to create an anonymous function.
const someFunction = function (param) {
// ...
};
someOtherFunction(function (param) {
// ...
});
const obj = {
someFunction: function (param) {
// ...
},
};
References:
- https://exercism.org/tracks/javascript/concepts/functions
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function
Backlinks