# Declarations vs Expressions — JavaScript

Source: https://www.geekswithgeeks.com/en/javascript/js-function-basics

> Two ways to define a function, and how hoisting differs.

## Function declaration

Hoisted — callable even before its definition appears in the code.

```js
function add(a, b) {
  return a + b;
}
console.log(add(2, 3));  // 5
```

## Function expression

Assigned to a variable — **not** hoisted the same way; usable only after the assignment line runs.

```js
const multiply = function (a, b) {
  return a * b;
};
console.log(multiply(2, 3));  // 6
```

## Named vs anonymous

Give function expressions a name (`const f = function greet() {}`) — it shows up in stack traces and makes debugging easier.
