Skip to content
Middle+5 views

Какие сущности относятся к глобальной, функциональной и блочной областям видимости?

Practice

Asked at

AI answer

In JavaScript, scope depends on the kind of declaration and the context.

  • Global: declarations at the top level of a classic script. var and function declarations can become properties of the global object; let, const, and class are available globally in the script, but are not its properties. In an ES module, the top level is the module scope, not the global scope.
  • Function: parameters and local var declarations inside a function are visible throughout that function. function declarations also have function scope.
  • Block: let, const, and class are visible only inside the nearest {} block; examples include the bodies of if, for, and while statements.

Unlike let and const, var is not limited to ordinary blocks.