
//export file, math.js
export const PI = 3.14159;
export function add(a, b) {
return a + b;
}
export default function multiply(a, b) {
return a * b;
}
//import하는 다른 js파일...
import multiply, { PI, add } from './math.js';
console.log(PI); // 3.14159
console.log(add(2, 3)); // 5
console.log(multiply(4, 5)); // 20
<head>에서 <script src = "">로 불러오는 것과는 무슨 차이일까?//예시
class MathOperations {
static add(x, y) {
return x + y;
}
}
console.log(MathOperations.add(5, 3)); // 출력: 8
//클래스: 청사진
class Car {
constructor(brand, model) {
this.brand = brand;
this.model = model;
}
drive() {
console.log(`${this.brand} ${this.model}이(가) 달립니다.`);
}
}
//인스턴스: 건물
let myCar = new Car("현대", "쏘나타");
let yourCar = new Car("기아", "K5");
class Person {
//prototype
sayHello() {
console.log("안녕하세요");
}
//static
static createGreeting(name) {
return `안녕하세요, ${name}님!`;
}
}

출처1: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/export
출처2: https://velog.io/@kim_unknown_/JavaScript-ES6#5-%ED%81%B4%EB%9E%98%EC%8A%A4-class
출처3: https://wouldyou.tistory.com/54