LoginSignup
1
1

More than 3 years have passed since last update.

Javascript 備忘録8<モジュール>

Posted at

■モジュールについて
→モジュールには2種類存在する
→ESMとCJS

■ESMとCJSの比較
→ESMはimport/exportを使用
→CJSはrequire/exportsを使用

■EMでモジュールを使用する

moduleA.js
export let hello = 'hello';

export function helloFn() {
    console.log('hello')
}
moduleB.js
// 別のモジュールからimportする
import { hello, helloFn } from './moduleA.js';
// 下のように as を使用して別の変数名にすることが可能
import { hello as ya, helloFn as fn }from './moduleA.js';

// 変数と関数が使用できるようになる
console.log(hello);
helloFn();
1
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
1
1