Immediately invoked function expression: Difference between revisions

Content deleted Content added
Replacing usurped ref with cite web template + usurped tag
Examples: Replacing usurped source with better one
Line 47:
 
==Examples==
The key to understanding design patterns such as IIFE is to realize that prior to ES6, JavaScript only featured [[Scope (computer science)#Function scope|function scope]] (thus lacking [[Scope (computer science)#Block scope|block scope]]), passing [[Call_by_reference|values by reference]] inside [[Closure (computer science)|closure]]s.<ref>{{cite book |last=Haverbeke |first=Marijn |title=Eloquent JavaScript |year=2011 |publisher=No Starch Press |isbn=978-1-59327-282-1 |pages=29–30}}</ref> This is no longer the case, as the ES6 version of JavaScript implements block scoping using the new <code>let</code> and <code>const</code> keywords.<ref>{{cite web |last1=Orendorff |first1=Jason |title=ES6 In Depth: let and const |url=https://es6-featureshacks.mozilla.org/#BlockScopedVariables2015/07/es6-in-depth-let-and-const/ |titlewebsite=ECMAScriptMozilla 6:Hacks New Features:the OverviewWeb anddeveloper Comparison - Block-Scoped Variablesblog |websitepublisher=es6-features.org[[Mozilla]] |access-date=March16 19,October 20182024 |archive-date=March31 18, 2018 |archive-url=https://web.archive.org/web/20180318064130/https://es6-features.org/#BlockScopedVariables |url-status=usurpedJul 2015}}</ref>
 
=== Evaluation context ===