What is the difference between function declaration and function expression?

// declaration
sayHi();
function sayHi() {
  console.log("Hi");
}

// expression
const sayBye = function () {
  console.log("Bye");
};
sayBye();

Output:

Tutorials Class - Output Window

Hi
Bye

The declaration is hoisted, so calling it above works. A function expression is not usable before the line where it is assigned: sayBye() above its definition gives an error. See JavaScript Functions.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.