4.6 Conclusion: Why does JavaScript have both normal global variables and the global object?
The global object is generally considered to be a mistake. For that reason, newer constructs such as const
, let
, and classes create normal global variables (when in script scope).
Thankfully, most of the code written in modern JavaScript, lives in ECMAScript modules and CommonJS modules. Each module has its own scope, which is why the rules governing global variables rarely matter for module-based code.