본문 바로가기

Develop/JavaScript

New Features in ES6

Fat Arrow Function

const getNumber = () => 1;

const getArray = () => [1, 2, 3];

const getObject = () => ({a: 1, b: 2, c: 3});

const withParam = (payload) => payload;

Object Manipulation

const {a, b} = result;

const {data: {a, b}} = result;

const firstObj = {a, b}; (Same as {a: a, b:b})

const secondObj = {c, d};

const mergeObj = { ...firstObj, ...secondObj};

Async Function(Promise)

const isTrue = (payload) => {
return new Promise((resolve, reject) => {
if (payload === true) {
resolve(true);
} else {
reject(false);
}
});
};

isTrue(true).then((result) => {
console.log('is true');
}).catch((error) => {
console.log('is not true');
});

Module Exports

export const a = 1;
export const b = 2;

const c = 3;
const d = 4;
export {c, d};

export default defaultModule;

Module Import

import defaultModule from './defaultModule';
import { a, b } from './defaultModule';

Block Scope (let)

var num = 0;

for (let i = 0; i < 5; i++) {
num += i;
}

console.log(num); // 10
console.log(i); // undefined

Template Literal (`)

const a = 1;
const b = 'b';

const c = `a: ${a} and b: ${b}`;


'Develop > JavaScript' 카테고리의 다른 글

IntersectionObserver  (0) 2019.09.27
Calculate Date  (0) 2018.12.24
[JavaScript] Post 날리기  (0) 2013.02.07
[Cygwin] 국내 url  (0) 2012.04.27
[JavaScript] 날짜로 요일 알아내는 함수  (0) 2012.04.27