Last Updated: February 25, 2016
·
503
· bhousman

Several ways of turning function declarations into expressions

Here are a variety of ways of writing Immediately Invoked Function Expressions (a.k.a. IIFE's in JavaScript):

var foo = function() {
  // Your code in here
}();

var foo = (function() {
  // Your code in here
})();

!function() { 
  // Your code in here
}();

+function() {
  // Your code in here
}();

-function() {
  // Your code in here
}();

~function() {
  // Your code in here
}();

new function() {
  // Your code in here
}();

new function(arg) {
  // Your code in here
}(arg);