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
JavaScript Functions
JavaScript Arrow Functions
Constructor Functions in JavaScript
JavaScript this Keyword
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What are arrow functions in JavaScript?
What is the this keyword in JavaScript?
What is the difference between call, apply and bind?
What is the difference between debounce and throttle?
What is the difference between function declaration and function expression?
What is a closure in JavaScript?