The following code does not produce 'foo' in output: (function(){console.log('foo'}())
I think that you mean this code: (function(){console.log('foo')}())