0

I came to know 'Function declarations and variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter.' -- JavaScript Scoping and Hoisting.

But which one hoisted first?

As a result of someone asked me at SegmentFault, I should give him a exact answer.

roc.an
  • 43
  • 6
  • Practically speaking, what difference does it make? – deceze Jan 06 '17 at 09:36
  • 1
    How can that matter ? "Hoisting" is a confusing concept. It's simpler to see it this way: "the scope of a variable declared with var or a function declaration is the whole function". Edit: thing which makes it more complex (and probably justifies the question) is that variable declaration moves with the assignation, contrary to the variable "equivalent". – Denys Séguret Jan 06 '17 at 09:36

1 Answers1

-1
function test() {
   return foo;
   var foo = true;
   function foo(){}

}

console.log(typeof test()) // function

functions are hoisted first See here for more informations

Community
  • 1
  • 1
Axnyff
  • 9,213
  • 4
  • 33
  • 37