0
0

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.

JavaScriptで注意すべき書き方メモ

Last updated at Posted at 2022-07-08

exportとimport

1.個々の機能をエクスポート

export1.js
export const add = (num1, num2) => {
  return num1 + num2;
  };
export const minus = (num1, num2) => {
  return num1 - num2;
};
import1.js
import { add, minus } from "./export1.js"
add(1, 2); // 3
minus(2, 1); // 1

importするとき { } でくくる

2.デフォルトエクスポート

export2.js
const add = (num1, num2) => {
  return num1 + num2;
  };
const minus = (num1, num2) => {
  return num1 - num2;
};
default export {add, minus};
import2.js
import calc from "./export1.js"
calc.add(1, 2); // 3
calc.minus(2, 1) // 1

デフォルトエクスポートの場合は { } でくくらない

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?