ES6
ECMAScript 2015
A major update to JavaScript. Introduced let/const, arrow functions, classes, and modules.
ECMAScript 2015
A major update to JavaScript. Introduced let/const, arrow functions, classes, and modules.
ES6 (ECMAScript 2015) is the most important update in the history of JavaScript, officially released in June 2015. It was the first major update in six years after its predecessor ES5 came out in 2009, and added numerous core features that form the foundation of modern JavaScript development.
The biggest change in ES6 is how variables are declared. To solve the function-scope problem of the old var, let and const with block scope were introduced. Arrow functions were also added, providing concise function expressions and solving the this binding problem.
The class syntax made prototype-based inheritance more intuitive to write, and the module system (import/export) greatly improved code separation and reusability. Promises solved callback hell and made asynchronous programming cleaner.
In addition, many features essential in practice were added, including template literals, destructuring assignment, the spread operator, default parameters, the Map/Set data structures, Symbol, and generators. Today, all modern browsers and Node.js fully support ES6.
// 1. let, const - 블록 스코프 변수 선언
const PI = 3.14159; // 재할당 불가
let count = 0; // 재할당 가능
// var는 함수 스코프, let/const는 블록 스코프
// 2. 화살표 함수 (Arrow Function)
const add = (a, b) => a + b;
const greet = name => `안녕하세요, ${name}님!`;
const fetchData = async () => {
const response = await fetch('/api/data');
return response.json();
};
// 3. 템플릿 리터럴 (Template Literal)
const user = { name: '홍길동', age: 25 };
console.log(`이름: ${user.name}, 나이: ${user.age}세`);
// 멀티라인도 가능
const html = `
<div class="card">
<h2>${user.name}</h2>
</div>
`;
// 4. 구조 분해 할당 (Destructuring)
const { name, age } = user;
const [first, second, ...rest] = [1, 2, 3, 4, 5];
// first: 1, second: 2, rest: [3, 4, 5]
// 5. 스프레드 연산자 (Spread Operator)
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5]; // [1, 2, 3, 4, 5]
const obj = { ...user, city: '서울' }; // 객체 병합
// 6. 클래스 (Class)
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name}가 소리를 냅니다.`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name}가 멍멍 짖습니다!`);
}
}
// 7. 모듈 (Modules)
// utils.js
export const sum = (a, b) => a + b;
export default class Calculator { /* ... */ }
// app.js
import Calculator, { sum } from './utils.js';
// 8. Promise
const fetchUser = (id) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (id > 0) resolve({ id, name: 'User' });
else reject(new Error('Invalid ID'));
}, 1000);
});
};
fetchUser(1)
.then(user => console.log(user))
.catch(err => console.error(err));
"This project uses ES6+ syntax, so if you need to support older browsers, you have to add transpiling with Babel. let/const and arrow functions don't work in IE11."
"In ES6, let and const have block scope, while var has function scope. const only prevents reassignment; an object's properties can still be changed. If you need immutability, use Object.freeze() or a library such as Immer."
"You can write this more cleanly with destructuring assignment. Instead of `const name = user.name; const age = user.age;`, you can reduce it to one line: `const { name, age } = user;`."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
const only prevents reassignment. `const arr = [1, 2]; arr.push(3);` is allowed. If you need immutability, create a new object with Object.freeze() or the spread operator.
Arrow functions do not have their own this and use the this of the enclosing scope. If you need this in an object method or event handler, use a regular function.
let/const are hoisted, but accessing them before initialization throws a ReferenceError. Get in the habit of always declaring variables at the top of the scope.
Setting a default value in the form `function greet(name = 'Guest')` reduces undefined-check logic. It is even more powerful when combined with destructuring.