What is a IIFE? JavaScript Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ม.ค. 2025

ความคิดเห็น • 9

  • @alandrews1000
    @alandrews1000 4 ปีที่แล้ว +1

    NICE

  • @CodingUnited
    @CodingUnited 4 ปีที่แล้ว

    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)

    • @VincentLabStudio
      @VincentLabStudio  4 ปีที่แล้ว

      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.

  • @DevsLikeUs
    @DevsLikeUs 4 ปีที่แล้ว

    Nice

  • @sqarcle
    @sqarcle 4 ปีที่แล้ว

    Just in 35 seconds. Nice. But better if you explained by some examples

    • @VincentLabStudio
      @VincentLabStudio  4 ปีที่แล้ว

      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.

  • @lukaser
    @lukaser 4 ปีที่แล้ว +1

    first