When I use an anonymous function to get value from a function it gives me undefined.
let objectStudent = {
name : "Muhammad Abdullah",
age : 21,
rollNo : "FA20-BCS-084",
Degree : "Computer Science",
compareTo : () => {
console.log(this.name);
}
}
objectStudent.compareTo()
output : undefined
But when I use it using function keyword, it gives correct output
compareTo : function(){
console.log(this.name);
}
output now : Muhammad Abdullah
why is this happening?