Skip to content

as

In JavaScript, as is a contextual keyword that gives a binding a different name in an import or export clause. It also names the namespace object that collects all of a module’s exports in import * as and export * as statements.

In an import declaration, { original as local } creates a local binding with a new name, which avoids clashes between modules that export the same name. In an export list, { local as exported } changes the name that other modules see. Renaming to or from default reads or creates a default export.

All of these forms are module syntax that only works in a module. Outside these clauses, as isn’t reserved and stays a valid identifier, even in modules. TypeScript’s as type assertions aren’t JavaScript syntax. Renaming and import * as came with modules in ES2015, and export * as followed in ES2020. Since ES2022, modules can export string names, such as "kebab-name", and as gives them a valid local name on import.

JavaScript as Keyword Syntax

The as keyword appears in these import and export forms:

Language: JavaScript Syntax
import { <name> as <alias> } from "<specifier>";
import * as <namespace> from "<specifier>";
export { <name> as <exportedName> };
export * as <namespace> from "<specifier>";

JavaScript as Keyword Examples

The strings.mjs module exports capitalize under the public name title:

Language: JavaScript Filename: strings.mjs
const capitalize = (text) => text[0].toUpperCase() + text.slice(1);
const reverse = (text) => [...text].reverse().join("");

export { capitalize as title, reverse };

Another module, main.mjs, renames one import and collects all exports in a namespace:

Language: JavaScript Filename: main.mjs
import { title as toTitle } from "./strings.mjs";
import * as strings from "./strings.mjs";

console.log(toTitle("ada"));
console.log(strings.reverse("stressed"));
console.log(Object.keys(strings));

Running main.mjs with Node.js prints the renamed and namespaced results:

Language: Shell
$ node main.mjs
Ada
desserts
[ 'reverse', 'title' ]

The function is called capitalize inside strings.mjs, but other modules see it as title. The namespace object lists the exported names, not the local ones.

Outside import and export clauses, as isn’t reserved, so it works as an ordinary identifier:

Language: JavaScript
> const as = "alias";
undefined
> as.toUpperCase()
'ALIAS'

JavaScript as Keyword Use Cases

  • Avoiding name clashes between imports from different modules
  • Giving long or unclear export names a shorter local name
  • Grouping a module’s exports under one namespace object
  • Exposing a public name that differs from the internal one

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026