This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for Interview Question on BFE.dev
162. What is the difference between function declaration and function expression?

Function declaration is a statement that declares a function and associates it with an identifier in the current scope. It is hoisted to the top of the current scope, so it can be called before it is declared in the code.

Example:

function helloWorld() {
  console.log("Hello World!");
}

Function expression, on the other hand, is creating a function and assigning it to a variable. The function can be anonymous or named. It is not hoisted to the top of the current scope, so it must be declared before it is called.

Example:

var hello = function() {
  console.log("Hello!");
};

In summary, the main difference between the two is the way they are defined and hoisted. Function declaration is defined as a statement and hoisted to the top of the scope, while function expression is defined as an expression and not hoisted to the top of the scope.