function add1(x, y) {
return x + y;
};
const add2 = (x, y) => {
return x + y;
};
const add3 = (x, y) => x + y;
const add4 = (x, y) => (x + y);
function not1(x) {
return !x;
};
const not2 = x => !x;
- 함수를 선언할 때 function 선언문 대신 ⇒ 기호로 함수 선언
function add(x, y) {
return x + y;
}
const add = (x, y) => {
return x + y;
}
- 함수 내부에 return문 밖에 없다면 ⇒ 기호 뒤에 return 할 식 적기
(매개변수가 1개라면 소괄호로 묶어주지 않아도 됨.)
const add = (x, y) => (x + y);
const add = (x, y) => x + y;
const not = x => !x;
var relationship1 = {
name: 'zero',
friends: ['nero', 'hero', 'xero'],
logFriends: function () {
var that = this;
this.friends.forEach(function (friend) {
console.log(that.name, friend);
});
},
};
relationship1.logFriends();
const relationship2 = {
name: 'zero',
friends: ['nero', 'hero', 'xero'],
logFriends() {
this.friends.forEach(friend => {
console.log(this.name, friend);
});
},
};
relationship2.logFriends();