The differences between arrow function and normal function

majidbabaeifar

Majid Babaeifar

Posted on July 27, 2022

The differences between arrow function and normal function
  1. In arrow function you can omit the curly braces and the return statement when the function is a 1 liner.
const myFunc = (a, b) => a + b
console.log(myFunc(1, 2))

// log : 3
Enter fullscreen mode Exit fullscreen mode
  1. In arrow function when it has only 1 argument, parenthesis is optional
const myFunc = a => a*a

console.log(myFunc(3))
// log : 9
Enter fullscreen mode Exit fullscreen mode
  1. In arrow function the this key word is automatically bound to the parent's context

this refers to the object that is currently executing the function

💖 💪 🙅 🚩
majidbabaeifar
Majid Babaeifar

Posted on July 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related