<s>
An	O
immediately	B-Language
invoked	I-Language
function	I-Language
expression	I-Language
(	O
or	O
IIFE	B-Language
,	O
pronounced	O
"	O
iffy	O
"	O
,	O
IPA	O
/ˈɪf.i/	O
)	O
is	O
a	O
programming	O
language	O
idiom	O
which	O
produces	O
a	O
lexical	B-Language
scope	I-Language
using	O
function	O
scoping	B-Language
.	O
</s>
<s>
It	O
was	O
popular	O
in	O
JavaScript	B-Language
as	O
a	O
method	O
to	O
support	O
modular	B-Architecture
programming	I-Architecture
before	O
the	O
introduction	O
of	O
more	O
standardized	O
solutions	O
such	O
as	O
CommonJS	B-Language
and	O
ES	O
modules	B-Architecture
.	O
</s>
<s>
Immediately	B-Language
invoked	I-Language
function	I-Language
expressions	I-Language
can	O
be	O
used	O
to	O
avoid	O
variable	O
hoisting	O
from	O
within	O
blocks	O
,	O
protect	O
against	O
polluting	O
the	O
global	O
environment	O
and	O
simultaneously	O
allow	O
public	O
access	O
to	O
methods	O
while	O
retaining	O
privacy	O
for	O
variables	O
defined	O
within	O
the	O
function	O
.	O
</s>
<s>
Immediately	B-Language
invoked	I-Language
function	I-Language
expressions	I-Language
may	O
be	O
written	O
in	O
a	O
number	O
of	O
different	O
ways	O
.	O
</s>
<s>
An	O
initial	O
parenthesis	O
is	O
one	O
case	O
where	O
the	O
automatic	O
semicolon	O
insertion	O
(	O
ASI	O
)	O
in	O
JavaScript	B-Language
can	O
cause	O
problems	O
;	O
the	O
expression	O
is	O
instead	O
interpreted	O
as	O
a	O
call	O
to	O
the	O
last	O
term	O
on	O
the	O
preceding	O
line	O
.	O
</s>
<s>
The	O
key	O
to	O
understanding	O
design	O
patterns	O
such	O
as	O
IIFE	B-Language
is	O
to	O
realize	O
that	O
prior	O
to	O
ES6	O
,	O
JavaScript	B-Language
only	O
featured	O
function	O
scope	O
(	O
thus	O
lacking	O
block	O
scope	O
)	O
,	O
passing	O
values	O
by	O
reference	O
inside	O
closures	B-Language
.	O
</s>
<s>
This	O
is	O
no	O
longer	O
the	O
case	O
,	O
as	O
the	O
ES6	O
version	O
of	O
JavaScript	B-Language
implements	O
block	O
scoping	B-Language
using	O
the	O
new	O
let	O
and	O
const	O
keywords	O
.	O
</s>
<s>
A	O
lack	O
of	O
block	O
scope	O
means	O
that	O
variables	O
defined	O
inside	O
(	O
for	O
example	O
)	O
a	O
for	B-Language
loop	I-Language
will	O
have	O
their	O
definition	O
"	O
hoisted	O
"	O
to	O
the	O
top	O
of	O
the	O
enclosing	O
function	O
.	O
</s>
<s>
IIFEs	B-Language
are	O
also	O
useful	O
for	O
establishing	O
private	O
methods	O
for	O
accessible	O
functions	O
while	O
still	O
exposing	O
some	O
properties	O
for	O
later	O
use	O
.	O
</s>
<s>
The	O
following	O
example	O
comes	O
from	O
Alman	O
's	O
post	O
on	O
IIFEs	B-Language
.	O
</s>
<s>
Originally	O
known	O
as	O
a	O
"	O
self-executing	O
anonymous	O
function	O
"	O
,	O
Ben	O
Alman	O
later	O
introduced	O
the	O
current	O
term	O
IIFE	B-Language
as	O
a	O
more	O
semantically	O
accurate	O
name	O
for	O
the	O
idiom	O
,	O
shortly	O
after	O
its	O
discussion	O
arose	O
on	O
comp.lang.javascript	O
.	O
</s>
