Last Modified: Friday, Feb 22, 2019
IIFE (Immediately Invoked Function Expression)
(function () {
})();
This is a nameless function which immediately invokes itself.
What this does is supports modularization by wrapping the content within a scope—preventing global namespace pollution & helping with separation of concerns.
Document-Ready Function
$( document ).ready(function() {
console.log( "ready!" );
});
Document-Ready IIFE
(function($) {
$(function() {
});
})(jQuery);
Check if element exists before running script
var check = document.getElementsByName("ELEMENT");
if(check.length != 0)
{
// Do something
}