DEV Community

Raj Maharjan
Raj Maharjan

Posted on

1 1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay