javascript中(function(){})()的用途

javascript中(function(){})()的用途,javascript,iife,Javascript,Iife,这样做的目的是什么 (function(){ console.log('holla at world'); })(); 而不是 console.log('holla at world'); 是否有一个例子说明必须使用第一种情况来完成某些事情 (function(){ console.log('holla at world'); })() 它立即调用函数表达式(IIFE),使用IIFE的目的是阻止全局范围污染

这样做的目的是什么

(function(){
   console.log('holla at world');
})();
而不是

console.log('holla at world');
是否有一个例子说明必须使用第一种情况来完成某些事情

(function(){
   console.log('holla at world');
})() 
它立即调用函数表达式(IIFE),使用IIFE的目的是阻止全局范围污染