The scope of JavaScript

What are the advantages and disadvantages of a design pattern like

js scope?
what gorgeous operations are bosses doing with scope?

Jul.16,2021

weigh the advantages and disadvantages of

Global scope = A function body access considers the nearest principle level weight principle
function scope = = when a function scope variable is out of scope, it will be cleaned up
let is considered as a local scope = = local access to avoid contamination in the global scope

actions

jquery is a typical example of a function scope. Large closures are used to avoid polluting global scope variables.
             

1. Advantages: scope protects variables from contamination
external access to internal variables

2. Difference: no dynamic scope
function internal variable references have nothing to do with the runtime, but are related to the location of the variable definition
see the following code

  

pollutes the environment, so use the global as little as possible. Let variable declarations that support block-level scopes are provided in ES6.

Menu