Blog

Function

JS

Arrow vs normal function

Arrow vs normal function

Ragav Kumar V

Ragav Kumar V

Aug 21, 2022 — Updated Sep 25, 2022 · 1 min read

  1. Arrow function - this does not point to anything
  2. Hence we do not use this in arrow function
  3. Shorter Syntax - one line function
    1. no return statement needed (one line function)
    2. not needed (one line function)

_10
const student = {
_10
firstName: "Gukesh",
_10
lastName: "D",
_10
fullName: () => {
_10
return `${this.lastName}, ${this.firstName}`;
_10
},
_10
};
_10
_10
console.log(student.fullName());
_10
// undefined, undefined


_10
const student = {
_10
firstName: "Gukesh",
_10
lastName: "D",
_10
fullName: function () {
_10
return `${this.lastName}, ${this.firstName}`;
_10
},
_10
};
_10
_10
console.log(student.fullName());
_10
// D, Gukesh

@ragavkumarv
swipe to next ➡️