Bootstrap css uses the following:
!function( $ ) {
}( window.jQuery )
That’s different than the self-invoking anonymous function call that I originally learned:
(function($) {
})(jQuery);
Q: Is that just preference you think? I mean the not symbol instead of enclosing it in parenthesis.
Yes, but using a unary
!operator, you can avoid a few bugs when you forget a semicolon before the IIFE, which can cause the()to be interpreted as a function call.Here the outer
()is interpreted as a function call. It’s trying to call whatever was returned from thealert()function, which of course returnsundefined, which isn’t a function.No troubles with this one, since the
!is a unary operator that only evaluates the operand to its right.