Search⌘ K

Specifying Function Expressions

Explore how JavaScript function expressions work, allowing functions to be assigned to variables and returned from other functions. Understand how this flexibility supports dynamic operations and prepares you for advanced concepts like recursion.

We'll cover the following...

JavaScript has a number of great things that are built on function expressions. Just like other objects, functions can be assigned to variables:

Node.js
var add = function (a, b) {
return a + b;
}

This assignment ensures that you can invoke the function through the variable, just like if it were a statically declared function:

Node.js
var add = function (a, b) {
return a + b;
}
console.log(add(12, 23));

...