“import” 및 "export"

민돌·2025년 3월 20일
0

JS

목록 보기
6/7

import / export

// util.js
export let apiKey = "adnasdoasflak1";

// app.js
import { apiKey } from "./util.js";
console.log(apiKey) 

default

// util.js
export default "adnasdoasflak1";

// app.js
import apiKey from "./util.js";

export default는 파일별로 하나만 존재 가능
이름이 없으니 반드시 할당해줘야함
하나의 값만 export 하고싶을때 사용하기 좋음

// util.js
export default "adnasdoasflak1";
export let apiKey = "adnasdoasflak1";
export let abe = "abc";

// app.js
import { apiKey, abc as content } from "./util.js";
console.log(content);

// app.js
import * as util from "./util.js";
console.log(util.apiKey);

0개의 댓글