// export
export default MyModule = () => console.log('foo')
// import
import MyModule from './MyModule' //it works
import foobar from './MyModule' //it also works,
module에서 오직 하나의 element 만을 export 할 때, 이름 신경 쓰지 않아도 되면 export default
default 키워드 사용 시에는 var, let, const 키워드는 사용 불가
{} 없이 임의의 이름으로 import 함
export const ( module을 이름 부여하여 export 하는 것)
// export
export const MyModule = () => console.log('foo')
// import
import MyModule from './MyModule' //returns empty object since there is no default export
import { MyModule } from './MyModule' //here it works because by exporting without 'default' keyword we explicitly exported MyModule
module에서 특정한 하나의 element 를 export 하려고 할 때, 이름 지정해서 하려면 export const
import
//lib.mjs
const pi = Math.PI;
function square(x) {
return x * x;
}
class Person {
constructor(name) {
this.name = name;
}
}
export { pi, square, Person };
// import
import * as lib from './lib.mjs';
import { pi as PI, square as sq, Person as P } from './lib.mjs';