I have searched similar questions on this site but they dont answer my particular query.
Hey, so I was wondering why would you use:
(function(){a+b;})();
instead of:
a+b;
Its a thing I see used often in this tutorial I'm following:
Link
Edit:
"real code for better context":
(function() {var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
Edit:
Didn't know it was called IIFE, thank you for the links.
Asked
Active
Viewed 43 times
-1

Sergey Andreev
- 49
- 1
- 9
-
There's a good explanation for using that construct, but your sample code doesn't seem to benefit from it. Can you post *real code* for better context? – Joseph Jul 22 '15 at 12:19
-
Your particular use case not covered by other answers seems fairly non-specific... – Álvaro González Jul 22 '15 at 12:19
-
Meanwhile, [Wikipedia](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression). – Álvaro González Jul 22 '15 at 12:21
-
See the explanation to Immediately Invoked Function Expression, [IIFE](http://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript). – Daniel B Jul 22 '15 at 12:22