(function() {
let number = 10;
console.log(number); // 10
})() // executed right away
console.log(number); // this will throw an error: number is not defined
VS
{
let number = 10;
console.log(number); //10
} // immediately invoked
console.log(number) // this will result in an error as well: number is not defined
Although both code snippets appear to achieve the same outcome, it seems like there may be a difference. Are these two approaches truly interchangeable or is there something I am overlooking?