Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

default — fallback clause and default export

The `default` keyword identifies a fallback clause in `switch` or a module's default export. It does not assign default parameter values and cannot be used as a variable name.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

switch (value) { case expression: statements; break; default: statements; }
export default expression;
export default function name() {}
export default class Name {}
import localName from "./module.js";

default is a reserved JavaScript keyword. You cannot declare a variable with let default = 1, but you can use it as a property name, as in const settings = { default: 1 }, and read settings.default.

In switch, default: identifies where execution starts when no case matches. Matching uses strict comparison, so 1 and "1" do not match. At most one default clause is allowed; it need not be last. It does not stop execution automatically: without break, return, or another interruption, execution continues into subsequent statements, including across case and default boundaries.

In a module, export default expression; exposes a value under the export name default. You can also export a function or class declaration, including an anonymous one. A module can have at most one default export alongside additional named exports. The consumer chooses a local name without braces: import localName from "./module.js";. These statements require a module context; an ordinary script is insufficient.

Default parameters and destructuring defaults use =, not the keyword default. The example demonstrates the fallback clause; each branch ends with return, so break is unnecessary.

Examples

function describe(value) {
  switch (value) {
    case 1:
      return "one";
    default:
      return "other";
  }
}

console.log(describe(1));
console.log(describe("1"));

Result

one
other

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources