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)

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay