Rescreve essa outra parte do artigo com as seguintes condições:


1. Reescreva em português.
2. Toda parte que utilizar uma palavra difícil ou se há uma parte difícil de entender, deixe ele mais claro e fácil de entender.
3. O artigo deve reescrito em forma de tutorial passo a passo.
4. Não elimine informações dadas no artigo.

"import

The static import declaration is used to import read-only live bindings which are exported by another module. The imported bindings are called live bindings because they are updated by the module that exported the binding, but cannot be re-assigned by the importing module.

In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module. In HTML, this is done by adding type="module" to the <script> tag. Modules are automatically interpreted in strict mode.

There is also a function-like dynamic import(), which does not require scripts of type="module".

Syntax
js
Copy to Clipboard
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { default as alias } from "module-name";
import { export1, export2 } from "module-name";
import { export1, export2 as alias2, /* … */ } from "module-name";
import { "string name" as alias } from "module-name";
import defaultExport, { export1, /* … */ } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";
defaultExport
Name that will refer to the default export from the module. Must be a valid JavaScript identifier.

module-name
The module to import from. Only single quoted and double quoted string literals are allowed. The evaluation of the specifier is host-specified. Most hosts align with browsers and resolve the specifiers as URLs relative to the current module URL (see import.meta.url). Node, bundlers, and other non-browser environments often define their own features on top of this, so you should find documentation for them to understand the exact rules. The module specifier resolution section also has more information.

name
Name of the module object that will be used as a kind of namespace when referring to the imports. Must be a valid JavaScript identifier.

exportN
Name of the exports to be imported. The name can be either an identifier or a string literal, depending on what module-name declares to export. If it is a string literal, it must be aliased to a valid identifier.

aliasN
Names that will refer to the named imports. Must be a valid JavaScript identifier.

The "module-name" may be followed by a set of import attributes, starting with the with keyword.

Description
import declarations can only be present in modules, and only at the top-level (i.e. not inside blocks, functions, etc.). If an import declaration is encountered in non-module contexts (for example, <script> tags without type="module", eval, new Function, which all have "script" or "function body" as parsing goals), a SyntaxError is thrown. To load modules in non-module contexts, use the dynamic import syntax instead.

All imported bindings cannot be in the same scope as any other declaration, including let, const, class, function, var, and import declaration.

import declarations are designed to be syntactically rigid (for example, only string literal specifiers, only permitted at the top-level, all bindings must be identifiers), which allows modules to be statically analyzed and linked before getting evaluated. This is the key to making modules asynchronous by nature, powering features like top-level await.

Forms of import declarations
There are four forms of import declarations:

Named import: import { export1, export2 } from "module-name";
Default import: import defaultExport from "module-name";
Namespace import: import * as name from "module-name";
Side effect import: import "module-name";
Below are examples to clarify the syntax.

Named import
Given a value named myExport which has been exported from the module my-module either implicitly as export * from "another.js" or explicitly using the export statement, this inserts myExport into the current scope.

js
Copy to Clipboard
import { myExport } from "/modules/my-module.js";
You can import multiple names from the same module.

js
Copy to Clipboard
import { foo, bar } from "/modules/my-module.js";
You can rename an export when importing it. For example, this inserts shortName into the current scope.

js
Copy to Clipboard
import { reallyReallyLongModuleExportName as shortName } from "/modules/my-module.js";
A module may also export a member as a string literal which is not a valid identifier, in which case you must alias it in order to use it in the current module.

js
Copy to Clipboard
// /modules/my-module.js
const a = 1;
export { a as "a-b" };
js
Copy to Clipboard
import { "a-b" as a } from "/modules/my-module.js";
Note: import { x, y } from "mod" is not equivalent to import defaultExport from "mod" and then destructuring x and y from defaultExport. Named and default imports are distinct syntaxes in JavaScript modules.

Default import
Default exports need to be imported with the corresponding default import syntax. The simplest version directly imports the default:

js
Copy to Clipboard
import myDefault from "/modules/my-module.js";
Since the default export doesn't explicitly specify a name, you can give the identifier any name you like.

It is also possible to specify a default import with namespace imports or named imports. In such cases, the default import will have to be declared first. For instance:

js
Copy to Clipboard
import myDefault, * as myModule from "/modules/my-module.js";
// myModule.default and myDefault point to the same binding
or

js
Copy to Clipboard
import myDefault, { foo, bar } from "/modules/my-module.js";
Importing a name called default has the same effect as a default import. It is necessary to alias the name because default is a reserved word.

js
Copy to Clipboard
import { default as myDefault } from "/modules/my-module.js";
Namespace import
The following code inserts myModule into the current scope, containing all the exports from the module located at /modules/my-module.js.

js
Copy to Clipboard
import * as myModule from "/modules/my-module.js";
Here, myModule represents a namespace object which contains all exports as properties. For example, if the module imported above includes an export doAllTheAmazingThings(), you would call it like this:

js
Copy to Clipboard
myModule.doAllTheAmazingThings();
myModule is a sealed object with null prototype. The default export available as a key called default. For more information, see module namespace object.

Note: JavaScript does not have wildcard imports like import * from "module-name", because of the high possibility of name conflicts.

Import a module for its side effects only
Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values.

js
Copy to Clipboard
import "/modules/my-module.js";
This is often used for polyfills, which mutate the global variables.

Hoisting
Import declarations are hoisted. In this case, that means that the identifiers the imports introduce are available in the entire module scope, and their side effects are produced before the rest of the module's code runs.

js
Copy to Clipboard
myModule.doAllTheAmazingThings(); // myModule.doAllTheAmazingThings is imported by the next line

import * as myModule from "/modules/my-module.js";"