# Declarations vs Expressions — JavaScript Fundamentals: From Syntax to Async

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

> Define functions as declarations or expressions and understand how hoisting affects each.

## 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.
