Sure. Suppose you assign to a new (previously unknown) variable, like this:
Then
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
.
Only if the code we are using is legacy code that was written in sloppy mode.
New code should really use strict
.
None. Just synonyms for the idea of a package (another synonym) of code that can add functionality to a program that imports it.
Those are the rules of the game. Modules are locked up, inaccessibly (as far as I know).
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.
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.
var App = {}; App.trig = trig; App.colors = colors;
This is storing two values in a dictionary. Consider:
In theApp
code above, trig
and colors
happen to be a dictionaries themselves, but
that's incidental. But let's see:
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.