Quiz

  1. I want more clarity on the purpose of modules. / could you talk more about the purpose of modules and what exactly they are? I don't know if I quite get it yet. / I don't really understand the concept of packaging. Can you explain why we do it. Is it the best way to reference to imported files?

    For sure.

    Modules are important when programs get large and/or are built by multiple people.

    They are an important part of a divide and conquer strategy by making it easier to truly divide the code into separate parts. A name in one space is different from the same name in other spaces.

    The order receiving, order fulfillment, order acknowledgement, and order billing modules might all have a global variable called currentOrder, and those would be separate and distinct names.

    They need to have clear interfaces as well, like stereo components and music players.

  2. In strict mode, can we use either var or let for a local variable?

    Yes, either is fine. The reading should have said var, let, or const, not just var.

    There are subtle distinctions between var and let that rarely matter, so they are almost always interchangeable.

    let is newer and shinier, so feel free to prefer that if you want.

    const was introduced at the same time as let, and it has some advantages at times.

    See strict mode

  3. can we talk more about how to use globalThis?

    Sure. Because the separation of modules is so strict in JavaScript, it can sometimes get in the way. globalThis is a "super" variable that exists in all namespaces. So module A can assign to it and module B can see that value.

    I find it useful for debugging, where module A can put a value into globalThis and I can see that value in the debugger.