> For the complete documentation index, see [llms.txt](https://betwinsouls.gitbook.io/full-stack-javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://betwinsouls.gitbook.io/full-stack-javascript/fucntion_expressions.md).

# Function Expressions

This function builds in memory immediately when the program loads.

```
function diffOfSquares (a, b) {
    return a*a - b*b;
    }
```

Function expressions build only when the program reaches their line of code.

```
var diff = function (a, b) {
 return a*a - b*b;
};

diff( 9, 5 ); // This is how we call the function
```

A variable that holds a function can be passed into other functions. Function expressions can give flexibility in choosing which functionality to build.

```
var greeting;
var newCustomer =  false;

if (newCustomer) {
  greeting = function() {
    alert("Welcome first timer!) {
    };
  } else {
    alert("Welcome back beloved customer");
  };
}
closeTerminal (greeting);
function closeTerminal(message){
  message();
}
```
