[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/export [Back]  [Original]

export - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

export

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2018 ..

export , ( ).

In this article

export { name1, name2, , nameN };
export { variable1 as name1, variable2 as name2, , nameN };
export let name1, name2, , nameN; //  var
export let name1 = , name2 = , , nameN; //  var, const

export default ;
export default function () {  } //  class, function*
export default function name1() {  } //  class, function*
export { name1 as default,  };

export * from ;
export { name1, name2, , nameN } from ;
export { import1 as name1, import2 as name2, , nameN } from ;
nameN

( import ()).

, :

  • :

    js
    export { myFunction }; //    
    export const foo = Math.sqrt(2); //  
    
  • ( ) ( ):

    js
    export default function () {} //  'export default class {}'
    //      
    

. , , .

(default), (). , , - . "", .

:

js
// "my-module.js"
function cube(x) {
  return x * x * x;
}
const foo = Math.PI + Math.SQRT2;
export { cube, foo };

(. import) :

js
import { cube, foo } from "my-module";
console.log(cube(3)); // 27
console.log(foo); // 4.555806215962888

export default

(fallback) , export default.

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

, :

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

Specification
ECMAScript 2027 LanguageSpecification
# sec-exports


Web Proxy Viewer  |  New URL  |  Original Page