Hoisting

Hoisting

  • Hoisting is a feature in JavaScript which allows access to function declarations before they’re defined

  • This means that we can place a function call before our function declaration and everything will still work as expected


Example

// Calling greetWorld() BEFORE it's function declararion
greetWorld()

// declaration of greetWorld()
function greetWorld() {
  console.log('Hello, World!')
}

JS Bin on jsbin.com

  • Notice how hoisting allowed greetWorld() to be called before the greetWorld() function was defined

  • This is not considered a best practice, but you should be aware that the feature exists