ES6: Export

Difference between export default and export

Export

// a.js
export const a = 1
export function hi {
  console.log('hi')
}
// b.js
import { a, hi } from 'a'

Export default

// a.js
const a = 1
export default a

// b.js
import a from 'a'

Syntax

// exports a function declared earlier
export { myFunction };
function myFunction(){};

// exports a constant
export const foo = 'bar'

// default exports function
export default function() {}

// default exports class
export default class {}

// default export can be imported with any name
let k; export default k = 12; // in file test.js

import m form './test'

Reference:

ES6:export default 和 export 区别 MDN web doc: export