bhylu.com

Advertisements

JS Hoisting

Declarations are processed before execution, but different declarations behave differently. A function declaration can be called earlier in its scope.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

console.log(addPlaces(3));
function addPlaces(count) {
  return count + 2;
}

What happens

The call succeeds and produces 5.