Arrow Function => in ES6

Arrow Function => in ES6

Arrow Function syntax

var greet = function (message, name) {
return message + name;
}
// arrow function
var arrowGreet1 = (message, name) => {
return message + name;
}
var arrowGreet2 = (message, name) => message + name;
var square = x => x ^ 2;

this in Arrow Function syntax

var deliveryBoy = {
name: "Joker",
handleMessage: function (message, handler) {
return handler(message);
},
receive: function () {
var that = this;
this.handleMessage("Hello, ", function (message) {
that.name;
console.log(message + that.name);
})
}
}
deliveryBoy.receive();
// arrow function
var arrowDelieveryBoy = {
name: "Joker",
handleMessage: (message, handler) => handler(message),
receive: function () {
this.handleMessage("Hello, ", message => console.log(message + this.name));
}
}
arrowDelieveryBoy.receive();