JSFiddle - React, Tailwind, and code Playground
by jsumners
JavaScript
// From the "Function Hoisting" section of http://oreilly.com/catalog/9780596806767/
function foo() {
alert("global foo");
}
function bar() {
alert("global bar");
}
function hoistMe() {
console.log(typeof foo); // "function"
console.log(typeof bar); // "undefined"
foo(); // "local foo"
bar(); // TypeError: bar is not a function
// function declaration:
// variable 'foo' and its implementation both get hoisted
function foo() {
alert("local foo");
}
// function expression:
// only variable 'bar' gets hoisted, not the implementation
var bar = function() {
alert("local bar");
};
}
hoistMe();