Interview Q&A / JavaScript

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between a function declaration and a function expression?

SHORT ANSWER

A declaration is hoisted with its body, so you can call it before the line it appears on. An expression assigns a function to a variable, and the variable follows var, let or const rules, so calling it early fails.

Explain it simply

A declaration is like a printed entry in a college directory: it exists from the start, so anyone can look it up even before the page where it is written. An expression is like a name added to a list on the day you actually reach that line.

js
function greet() {}          // declaration
const greet2 = function () {}; // expression

With a declaration, the whole function is hoisted to the top of its scope. With an expression, only the variable is hoisted: var gives undefined until assignment, and let or const throw a ReferenceError in the temporal dead zone.

Example

js
console.log(add(2, 3));      // Output: 5

function add(a, b) {
  return a + b;
}

try {
  console.log(mul(2, 3));
} catch (e) {
  console.log(e.name);       // Output: ReferenceError
}

const mul = function (a, b) {
  return a * b;
};

With var mul = function... the error would be a TypeError ("mul is not a function"), because mul would be undefined at that point.

What to say in the interview

"Declarations are fully hoisted, so they can be called before they appear. Expressions are values assigned to a variable, so only the variable is hoisted and the function is unavailable until that line runs. Arrow functions are always expressions."

Common mistakes

  • Saying that function expressions are not hoisted at all. The variable is hoisted, the function value is not.

#javascript#functions#hoisting

Related questions

Practise more JavaScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open JavaScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.