What would be a use case for immediately invoked functions in JavaScript? [duplicate]

If we define a function

(function(){ 
  console.log("");
})();

then it is invoked immediately.
We could define the same function

function foo(){ 
  console.log("");
}
foo();

I fail to see a good use case for this, but if there is one, then I don’t see why we not just define a normal function and call it. Why should we use immediately invoked functions and what are their advantages?