7

Possible Duplicate:
(…()) vs. (…)() in javascript closures

Is there any difference between (function(){ ... })(); and (function(){ ... }()); ?

In this example both works the same way:

window.onload=function() {

    var a = (function(i){
        return "aaa" + i;
    })(1);


    var b = (function(i){
        return "bbb" + i;
    }(2));

    console.log("a: "+ a);
    console.log("b: "+ b);

};
Community
  • 1
  • 1
Piotr Jasiun
  • 996
  • 5
  • 8
  • 2
    No difference, just a manner of writing. Both are versions of a **self-executing anonymous function** (or, Immediately Invoked Function Expression if you so prefer). – Rikonator Jan 09 '13 at 16:10
  • 1
    Yeah I hate the "self-executing" bit. They are no more "self-executing" than any other piece of Javascript code. – Lightness Races in Orbit Jan 09 '13 at 16:13
  • I think the term that is more accepted term is [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE). (Immediately Invoked Function Expression) – Joey Carlisle Dec 28 '21 at 20:34

0 Answers0