default 关键字可以在 JavaScript 的两种情况下使用：在 `switch` ，或 `export` 中。

## 语法

在`switch` 语句中使用:

    switch (expression) {
      case value1:
        //当表达式的值和value1匹配执行这里的语句
        [break;]
      default:
        //当表达式的值没有匹配，执行这里的语句
        [break;]
    }

在`export` 中使用：

    export default nameN

## 描述

更多细节，参见

- `switch` 语句和
- `export` 语句页面。

## 示例

### 在`switch`语句中使用`default`

在以下示例中，如果`expr`为“Oranges”或“Apples”，程序将匹配“Oranges”或“Apples”的值并执行相应的声明。在任何其它情况下，`default`关键字将执行关联的语句。

    switch (expr) {
      case "Oranges":
        console.log("Oranges are $0.59 a pound.");
        break;
      case "Apples":
        console.log("Apples are $0.32 a pound.");
        break;
      default:
        console.log("Sorry, we are out of " + expr + ".");
    }

### 在`export`语句中使用`default`

如果要导出单个值或需要模块的回掉值，则可以使用默认导出：

    // module "my-module.js"
    let cube = function cube(x) {
      return x * x * x;
    }
    export default cube;

然后，在另一个脚本中，默认导出将直接被导入：

    // module "my-module.js"
    import myFunction from 'my-module';
    console.log(myFunction(3)); // 27

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript 2015 (6th Edition, ECMA-262) switch statement | Standard |
ECMAScript 2015 (6th Edition, ECMA-262) Exports | Standard |
ECMAScript Latest Draft (ECMA-262) switch statement | Draft |
ECMAScript Latest Draft (ECMA-262) Exports | Draft |

## 浏览器兼容

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

| Desktop | Mobile | Server
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js
`default` keyword in `switch` | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 1 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes
`default` keyword with `export` | Chrome Full support 61 | Edge Full support 16 Full support 16 Full support 15 Disabled Disabled From version 15: this feature is behind the `Experimental JavaScript Features` preference. | Firefox Full support 60 Full support 60 No support 54 — 60 Disabled Disabled From version 54 until version 60 (exclusive): this feature is behind the `dom.moduleScripts.enabled` preference. To change preferences in Firefox, visit about:config. | IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android No support No | Chrome Android Full support 61 | Edge Mobile Full support Yes | Firefox Android Full support 60 Full support 60 No support 54 — 60 Disabled Disabled From version 54 until version 60 (exclusive): this feature is behind the `dom.moduleScripts.enabled` preference. To change preferences in Firefox, visit about:config. | Opera Android Full support 47 | Safari iOS Full support 10.1 | Samsung Internet Android No support No | nodejs ?

### Legend

Full support
  Full support
No support
  No support
Compatibility unknown
  Compatibility unknown
User must explicitly enable this feature.
  User must explicitly enable this feature.

## See also

- `export`
- `switch`