What is file scope in javascript

Deadly 提交于 2020-12-11 04:26:36

问题


What is variable declared within file scope in javascript?
Is there anything file scope, considering multiple files are used in an app.


回答1:


ES6 modules form their own file scope (as if the entire contents of the file were wrapped in a function).

Variables declared in a module are completely inaccessible from outside that module (unless they're exported).




回答2:


In JavaScript, there are only 3 types of scope:

  1. Global Scope (i.e. every variable/function defined outside functions in a file or multiple files)
  2. Functional Scope (i.e. every variable/function defined within the function)
  3. Closure Scope (i.e. code block/function having access to its surrounding lexical scope)


来源:https://stackoverflow.com/questions/44916179/what-is-file-scope-in-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!