JSFiddle - React, Tailwind, and code Playground
by fparent
JavaScript
// Let say a FOO variable was declared by a third-party script
// and called before our main script file:
var FOO = function() {
var label = 'BAR';
console.log( label );
};
// console: BAR
FOO();
var FOO = { label: 'BIZ' };
console.log( typeOf( FOO ) );
// Now let's say we call our main JavaScript file, but
// doesn't overwrite the original namespace object;
// if the previously declared object is not an IIFE,
// our object will be discarded
var FOO = FOO || (function() {
var label = 'FOO';
// Won't be executed
console.log( label );
}());
// Now if we overwrite the original namespace instead,
// the code will eb executed correctly
var FOO = (function() {
var label = 'BAZ';
// console: BAZ
console.log( label );
}());