What is the difference between a function declaration and a function expression?
Both create a function value. The difference is what the parser sees at the start of the statement. A declaration begins with the keyword function in statement position, so the engine creates the function and attaches it to the name before any code runs. An expression is the keyword function used as a value, assigned to a variable, stored in an object or passed as an argument, and it only comes into existence when that expression is evaluated.
That single difference produces several observable differences.
Hoisting. A declaration is hoisted with its body attached, so you can call it from a line above its definition. An expression behaves like any other value: its binding exists from the start of the scope, but the value only arrives when the assignment runs, and reading it earlier throws.
Naming. A declaration always has a name. An expression can be anonymous, and when you assign one to a variable the engine infers the name from the variable, which is why you see the name property filled in for you.
Position in a statement. A declaration is a statement and can stand alone. An expression is part of a larger expression, so it needs to be inside an assignment, a call argument, a return statement or similar.
This binding. Both are ordinary functions with their own this binding and their own arguments object. Neither is an arrow function; arrows are a separate syntax with different rules.
The common mistake is treating the two as interchangeable when they are not. A function expression stored in a constant is often the safer choice, because the behaviour is uniform: one rule for every function, no hoisting surprises and no accidental globals.