-2

I was reading about this on W3, but I want to know more information about the differences and advantages of declaring a regular function versus declaring a function stored in a variable.

Regular:

function test(){
   // code
}

With Variable:

var test = function() {
  // code
}

1 Answers1

0

It mostly comes to Javascript hoisting.

Hoisting is JavaScript's default behavior of moving declarations to the top.

Learn more here

Basically what it means:

Inevitably, this means that no matter where functions and variables are declared, they are moved to the top of their scope regardless of whether their scope is global or local.

Of note, however, is the fact that the hoisting mechanism only moves the declaration. The assignments are left in place.

pho7on
  • 394
  • 1
  • 10