Quiz

  1. Can you explain more about global variable under strict mode?

    Sure. Suppose you assign to a new (previously unknown) variable, like this:

    
        alisia = 15;
        bettty = 17;
    
    

    Then

    • In sloppy mode, it creates that variable.
    • In strict mode, it complains that you didn't declare that variable.

    Generally, we prefer the latter, because the previously unknown variable might be a typo or other error.

    If we want to create (declare) a new variable, it's easy enough to use var, let or const.

  2. Is there any case that we want to use sloppy mode instead of strict mode

    Only if the code we are using is legacy code that was written in sloppy mode.

    New code should really use strict.

  3. What is the difference between a module and a library?

    None. Just synonyms for the idea of a package (another synonym) of code that can add functionality to a program that imports it.

  4. When debugging, why is the main module not reachable in the console?

    Those are the rules of the game. Modules are locked up, inaccessibly (as far as I know).

  5. Can you explain globalThis? / could you go over globalThis? Thank you

    Glad to. There is one name (at least) that exists in all namespaces (modules), and that is globalThis.

    So, if we put some value in globalThis, we can access that value from any module.

  6. What’s the difference between loading as a script and as a module?

    Module code goes in its own bucket, separate from code in other buckets. This minimizes possible naming conflicts. That's a good thing.

    But it also makes the code inaccessible, which can make debugging harder.

  7. I don't get what this code is doing. What is stored in App here?
    var App = {};
    App.trig = trig;
    App.colors = colors;
    

    This is storing two values in a dictionary. Consider:

    
        var mydict = {};
        mydict.age = 62;
        mydict.hair = 'mostly grey';
    
    
    In the App code above, trig and colors happen to be a dictionaries themselves, but that's incidental. But let's see:
    
        var fred = {};
        fred.age = 17;
        fred.hair = 'red';
    
        var dictOfDicts = {};
        dictOfDicts.scott = mydict;
        dictOfDicts.fred = fred;
    
    
  8. Can we only import parts of variables from an additional module? Are we creating a separate dictionary and importing that dictionary to the main module? Thank you!

    I'm not sure what you mean by "parts of variables".

    Variables have values and names. We import the names into another module, thereby gaining access to the values.