Function Expression vs. Function Declaration

Jae Yeon JungJae Yeon Jung
1 min read

Format

// Function Expression
const expression = function () {
    console.log('this is a function expression);
}

// Function Declaration
function declaration () {
    console.log('this is a function declaration);
}

Difference

  1. Name

    • A function expression is a function assigned to a variable (which has a name). So the function itself can be anonymous.

    • However, a function declaration must include a name.

  2. Hoisting

    • Hoisting is allowed only in the function declaration.

        expression(); // error
        declaration(); // this is a function declaration
      
        const expression = function () {
            console.log('this is a function expression');
        }
      
        function declaration () {
            console.log('this is a function declaration');
        }
      
0
Subscribe to my newsletter

Read articles from Jae Yeon Jung directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jae Yeon Jung
Jae Yeon Jung