can we use arrow function as a callback function in javascript code example
Example 1: arrow func in javascript
const greet = (who) => {
return `Hello, ${who}!`;
};
greet('Eric Cartman'); // => 'Hello, Eric Cartman!'
Example 2: javascript this inside arrow function
function A() {
this.val = "Error";
(function() {
this.val = "Success";
})();
}
function B() {
this.val = "Error";
(() => {
this.val = "Success";
})();
}
var a = new A();
var b = new B();
a.val // "Error"
b.val // "Success"