liveBook · Manning

Export keyword

As explained in Secrets of the JavaScript Ninja, Third Edition

The export keyword declares bindings or values that other modules can import.

A module’s declarations are private by default. Prefix a `const`, `let`, or `function` declaration with `export` to make its value available to other modules. Exporting does not change behavior inside the declaring module. section 13.1.1

Listing 13.1 Exporting named values
export const homeIsland = "Tsushima"; #A
export function getOccupation(place: string) { #B
  return `Ghost of ${place}`; #B
} #B

This example exports a string constant and a function under their declared names. section 13.1.1

Projects may instead gather exports in one declaration, making a module’s public interface easier to scan and review. section 13.1.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains inline named exports and notes grouped declarations, alongside default exports and import forms.
Examples
Demonstrates named exports with a string constant and a function.
What you can do after
Apply it by exporting declarations and importing their names in another module.
How it connects
Pairs exports with ECMAScript modules, import declarations, named imports, and default exports.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.