Nice video, but isn't it easier to just have an anonymous block statement like the following if you need to localize a scope? { const x = 23; console.log(x); // 23 } console.log(x); // Error: x is not defined I usually only see IIFEs when people need async/await. Edit: This won't work for function/class scope defined variables, though. (defined with var instead of let/const)
Personally I mainly use IIFEs for async/await and not for isolating scope, but it is also one of the uses of them, so that was mainly why I mentioned it. And I don't have much experience with block statements, so I can't say which is better and which you should use when and where. But I think you answered your own question pretty good.
I know it could be better, but I'm just experimenting with TH-cam shorts. But don't worry, it will not replace my usual content. If I make another, I'll try to include some more examples. And thanks for the feedback, it is always appreciated.
NICE
Thanks
Nice video, but isn't it easier to just have an anonymous block statement like the following if you need to localize a scope?
{
const x = 23;
console.log(x); // 23
}
console.log(x); // Error: x is not defined
I usually only see IIFEs when people need async/await.
Edit: This won't work for function/class scope defined variables, though. (defined with var instead of let/const)
Personally I mainly use IIFEs for async/await and not for isolating scope, but it is also one of the uses of them, so that was mainly why I mentioned it. And I don't have much experience with block statements, so I can't say which is better and which you should use when and where. But I think you answered your own question pretty good.
Nice
Thanks
Just in 35 seconds. Nice. But better if you explained by some examples
I know it could be better, but I'm just experimenting with TH-cam shorts. But don't worry, it will not replace my usual content. If I make another, I'll try to include some more examples. And thanks for the feedback, it is always appreciated.
first