JSFiddle - React, Tailwind, and code Playground
by darcyclarke
JavaScript
function foo () {};
// foo is a "function"...
var bar = function () {};
// bar is a "function" too, but...
// bar also happens to be a "method"...
// "Why is this?", you may ask. Well, a "method" is essentially the same thing as a "function"; Although, semantically, a "method" is defined as being associated with an "object" where it can derive/inherit attributes/data. This is actually where the term "Object-Oriented Programming" comes from. Although not explicit, in JavaScript, any variable definition (ie. "var = ..."), in the global scope, gets hoisted, automatically, and bound to the "window" object. YAY MAGIC!
// See for yourself...
console.dir( window.foo ); // named function... doesn't get hoisted
console.dir( window.bar ); // function definition... does get hoisted
console.log( window.bar === bar ); // operation to show equality