fungsi normal vs fungsi panah
// Normal Function
let add = function (num1, num2) {
return num1 + num2;
}
// Arrow Function
let add = (num1, num2) => num1 + num2;
madhav
// Normal Function
let add = function (num1, num2) {
return num1 + num2;
}
// Arrow Function
let add = (num1, num2) => num1 + num2;
//* main difference is arrow functions do not have their own this
let user = {
name: "HEllo world",
functTest() {
console.log("----functTest---", this.name) // HEllo world
},
arrowTest: () => {
console.log("----arrowTest----", this.name) // undefined
}
}
user.functTest()
user.arrowTest()