ECMAScript 는 JavaScript 프로그래밍 언어가 사용하는 표준
2015년에 출시되었기 때문에 ECMAScript 2015로도 알려져 있음 (ES5는 2009년)
var fullName = 'John Moore';
var age = 25;
var gender = 'Male';
var city = 'London'
// ES5
var student = { fullName: fullName, age: age, gender: gender, city: city };
// ES6
var student = { fullName, age, gender, city };
var target = { firstName: 'John', age: 25 }
var source = { fullName: 'John Moore', gender: 'Male', city: 'London' }
//ES5
var updatedTarget = Object.assign(target, source); //changes the target variable
//ES6
var updatedTarget = { ...target, ...source};
var student = { fullName: 'John Moore', age: 25, gender: 'Male', city: 'London' };
//ES5
var fullName = student.fullName;
var age = student.age;
var gender = student.gender;
var city = student.city;
//ES6
var { fullName, age, gender, city } = student;
var fullName = 'John Moore';
var age = 25;
var gender = 'Male';
var city = 'London'
//ES5
var intro = 'Hello, I am ' + fullName + '. I am ' + age + ' years old ' + gender + ' student from ' + city + '.';
//ES6
var intro = `Hello, I am ${fullName}. I am ${age} years old ${gender} student from ${city}.`;
//ES5
function sayHello(name) {
console.log('Hello, ' + name);
}
//ES6
const sayHello = (name) => {
console.log(`Hello, ${name}`);
}
const sayHello = name => console.log(`Hello, ${name}`); //You can ignore parenthesis, if the function contains a single parameter and only one statement
//ES5
var App = require('./App');
//ES6
import App from './App';
import { Header, Sticky } from '@primer/components'; //child modules
var Student = { fullName: 'John Moore', age: 25, gender: 'Male', city: 'London' };
//ES5
module.exports = Student;
//ES6
export default Student;
export const fullName = 'John Moore'; //child variables
export const age = 25;