인디노트

ES5 , ES6 본문

개발 플랫폼 및 언어/JavaScript

ES5 , ES6

인디개발자 2021. 2. 7. 08:25
ES5
var name = req.body.name
var age = req.body.age
var email = req.body.email

ES6
const {name, age, email} = req.body



ES5
var name = 'hak'
var age = 27
var email = 'code.ryan.lee@gmail.com'

var datas = {
    name: name,
    age: age,
    email: email
}

ES6
let name = 'hak'
let age = 27
let email = 'code.ryan.lee@gmail.com'

let datas = {name, age, email}
let datas2 = {username: name, age, email}





ES5
var username = req.body.username
if ( !username ) {
    throw "'username' must required. Your input: " + username  + "."
}

ES6
let {username} = req.body
if ( !username ) {
    throw `'username' must required. Your input: ${username}.`
}



ES5
var greeting = function(username, date, message) {
    username = typeof username !== 'undefined' ? username : 'anonymous'
    date     = typeof date     !== 'undefined' ? date     : new Date()
    message  = typeof message  !== 'undefined' ? message  : 'hello'

    return message + ' ' +  username + ' at ' + date
}

ES6
const greeting = (username='anonymous', date=new Date(), message='hello') => {
    return `${message} ${username} at ${date}`
}


sanghaklee.tistory.com/54

반응형
Comments