DEV Community

Raj Maharjan
Raj Maharjan

Posted on

JavaScript Function declaration vs expression

Function declaration:

Function expression

  1. appear in the global scope
  2. appear inside a function

Features: Hoisting
Available: Anywhere inside scope (global and local)

Function expression:

Alt Text

  1. can be assigned to a variable
  2. can be assigned to a property
  3. can appear in function invocations as parameters

Features: Closures, Callbacks, IIFE (Immediately Invoked Function Expressions)
Available: after the line it is declared

Top comments (0)