I'am studying the behaviour of Immediatly Invoked Function Expressions (IIFE) and while doing that I encounterd the following situation.
(function () {
document.write("bar");
})
(function () {
document.write("foo");
}());
I thought that the first is just a grouping operator with a function expression inside without calling it. The second is a grouping operator as well with a function expression but now with the call of that function.
What I find strange is that both are invoked, why is that?
(function () {
document.write("bar");
})
var x = 1;
(function () {
document.write("foo");
}());
When I break the two by inserting a variable declaration in between, it's just writes foo. This is what I expected.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…