//es5 문법
function greetings (name) {
return 'hello ' + name
}
//es6 문법
const greetings = (name) => {
return `hello ${name}`;
}
//es5 문법
var obj1 = {a : 1, b : 2}
var obj2 = {a : 2, c : 3, d : 4}
var obj3 = Object.assign (obj1, obj2)
//es6 문법
const obj1 = {a : 1, b : 2}
const obj2 = {a : 2, c : 3, d : 4}
const obj3 = {... obj1, ... obj2}
//es5 문법
var obj1 = { a: 1, b: 2, c: 3, d: 4 }
var a = obj1.a
var b = obj1.b
var c = obj1.c
var d = obj1.d
//es6 문법
const obj1 = { a: 1, b: 2, c: 3, d: 4 }
const {
a,
b,
c,
d
} = obj1
//es5 문법
var a = 1
var b = 2
var c = 3
var d = 4
var obj1 = { a: a, b: b, c: c, d: d }
//es6 문법
var a = 1
var b = 2
var c = 3
var d = 4
var obj1 = { a, b, c, d }
//es5 문법
function isGreater (a, b, cb) {
var greater = false
if(a > b) {
greater = true
}
cb(greater)
}
isGreater(1, 2, function (result) {
if(result) {
console.log('greater');
} else {
console.log('smaller')
}
})
//es6 문법
const isGreater = (a, b) => {
return new Promise ((resolve, reject) => {
if(a > b) {
resolve(true)
} else {
reject(false)
}
})
}
isGreater(1, 2)
.then(result => {
console.log('greater')
})
.catch(result => {
console.log('smaller')
})
//es5 문법
var myModule = { x: 1, y: function(){ console.log('This is ES5') }}
module.exports = myModule;
//es6 문법
const myModule = { x: 1, y: () => { console.log('This is ES5') }}
export default myModule;
//es5 문법
var myModule = require('./myModule');
//es6 문법
import myModule from './myModule';
import {x, y, z} from './myModule';