11.2 Scripts

Source files that contain no module import or export declarations are classified as scripts. Scripts form the single global namespace and entities declared in scripts are in scope everywhere in a program.

  ImplementationScript:   ImplementationScriptElementsopt

  ImplementationScriptElements:   ImplementationScriptElement   ImplementationScriptElementsImplementationScriptElement

  ImplementationScriptElement:   ImplementationElement   AmbientModuleDeclaration

  ImplementationElement:   Statement   LexicalDeclaration   FunctionDeclaration   GeneratorDeclaration   ClassDeclaration   InterfaceDeclaration   TypeAliasDeclaration   EnumDeclaration   NamespaceDeclaration   AmbientDeclaration   ImportAliasDeclaration

  DeclarationScript:   DeclarationScriptElementsopt

  DeclarationScriptElements:   DeclarationScriptElement   DeclarationScriptElementsDeclarationScriptElement

  DeclarationScriptElement:   DeclarationElement   AmbientModuleDeclaration

  DeclarationElement:   InterfaceDeclaration   TypeAliasDeclaration   NamespaceDeclaration   AmbientDeclaration   ImportAliasDeclaration

The initialization order of the scripts that make up the global namespace ultimately depends on the order in which the generated JavaScript files are loaded at run-time (which, for example, may be controlled by <script/> tags that reference the generated JavaScript files).