0

They both return the same result. But what is the difference?

(function (val) {
    console.log("val1: ", val);
}("FOO"));


(function (val) {
    console.log("val2: ", val);
})("FOO");


val1:  FOO
val2:  FOO 
Green
  • 28,742
  • 61
  • 158
  • 247
  • None. Why do you think there was any? – Bergi Oct 10 '14 at 12:09
  • @Bergi, I usually use the second one. But yesterday I was implementing the Slick lib (a jQuery carousel) and they use the first version. So, I'm curious if there is a difference. – Green Oct 10 '14 at 12:12
  • IMO the question *if* there is a difference between `(function(){})()` and `(function(){}())` and why `function(){}()` doesn't work is a valid question... – Mathias Oct 10 '14 at 12:16
  • 1
    @Mathias: Yes - an [answered one](https://stackoverflow.com/questions/1634268/explain-javascripts-encapsulated-anonymous-function-syntax)… – Bergi Oct 10 '14 at 12:24

0 Answers0