javascript - Why are anonymous, self-executing function used instead of just writing the commands -


i have searched similar questions on site dont answer particular query.
hey, wondering why use:
(function(){a+b;})();
instead of:
a+b;
thing see used in tutorial i'm following:
link
edit:
"real code better context":
(function() {var requestanimationframe = window.requestanimationframe || window.mozrequestanimationframe || window.webkitrequestanimationframe || window.msrequestanimationframe; window.requestanimationframe = requestanimationframe; })();
edit:
didn't know called iife, thank links.

just encapsulation.for not visible in outer scope.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -