Arrow vs normal function
- Arrow function -
this
does not point to anything - Hence we do not use
this
in arrow function - Shorter Syntax - one line function
- no return statement needed (one line function)
- not needed (one line function)
_10const student = {_10 firstName: "Gukesh",_10 lastName: "D",_10 fullName: () => {_10 return `${this.lastName}, ${this.firstName}`;_10 },_10};_10_10console.log(student.fullName());_10// undefined, undefined
_10const student = {_10 firstName: "Gukesh",_10 lastName: "D",_10 fullName: function () {_10 return `${this.lastName}, ${this.firstName}`;_10 },_10};_10_10console.log(student.fullName());_10// D, Gukesh
@ragavkumarv
swipe to next ➡️