3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

export, export defaultの違い

Last updated at Posted at 2022-11-22

export

export const a = 1;
export const b = 2;
import a from './test';

console.log(a);

export default

let k; export default k = 12;
import m from './test'; // k がデフォルトエクスポートなので、インポートする k の代わりに m を使用することができる点に注意してください
console.log(m);        // log 12 になる

exportとexport defaultの違い

exportとexport defaultの違いは、exportは複数定義できるが、export defaultは1つしか定義できない。

また、export defaultはimport時に名前を自由に変更できるが、exportは名前を変更できない。

参考

export - JavaScript | MDN

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?